comp.lang.ada
 help / color / mirror / Atom feed
* gethostname (Was: SunAda question)
@ 1993-07-21 10:27 Karl A. Nyberg
  0 siblings, 0 replies; 3+ messages in thread
From: Karl A. Nyberg @ 1993-07-21 10:27 UTC (permalink / raw)


In article <9307202026.aa28700@Paris.ics.uci.edu> kanderso@mabillon.ICS.UCI.EDU
 (Kenneth Anderson) writes:

>Frankly, I'm offended!  This completely violates everything that I've
>been taught about Ada functions! The actual parameters of a function
>should not be modified.  A function should only return one value.
>
>Wow, this is ugly! (Me thinks me smells a C programmer lurking
>                    behind that "function"...)
>
>Thanks again to Keith, Karl, and Tim for their help... I'll use gethostname
>but I don't have to like it...

You're confusing languages with operating systems.  What you want to say is
that you'll use UNIX, but you don't have to like it.  The UNIX system call
could be rewritten to be more "pure", in terms of your mathematical notion
of what a function should do, but I wouldn't hold my breath...

-- Karl --

p.s. again - look at what the POSIX standard says.  I'll bet the P1003.5
guys have done a better job at this.  Right, Dave?


-- 
Karl Nyberg			-- karl@grebyn.com
Grebyn Corporation		-- 1-703-281-2194
P. O. Box 497			-- Yes, I speak for the company.
Vienna, VA 22183-0497		-- I own it.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gethostname (Was: SunAda question)
@ 1993-07-21 14:56 David Emery
  0 siblings, 0 replies; 3+ messages in thread
From: David Emery @ 1993-07-21 14:56 UTC (permalink / raw)


>Frankly, I'm offended!  This completely violates everything that I've
>been taught about Ada functions! The actual parameters of a function
>should not be modified.  A function should only return one value.

The Verdix package "Unix" is what is called a "thin binding", in that
it simply recasts an existing C operation, semantics and all, in Ada
syntax.  

Your better solution is to use the POSIX/Ada binding.  See
"POSIX.System_Name" and "POSIX.Host_Name" functions.

				dave

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gethostname (Was: SunAda question)
@ 1993-07-21 15:26 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.
  0 siblings, 0 replies; 3+ messages in thread
From: cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland. @ 1993-07-21 15:26 UTC (permalink / raw)


In article <9307202026.aa28700@Paris.ics.uci.edu> 
kanderso@mabillon.ICS.UCI.EDU (Kenneth Anderson) writes:

>   The function gethostname is defined as :
>
>           function gethostname(name: address; namelen: integer)
>             return status_code;
>
>
>
>
>   Turns out that this function is not a function. It actually returns TWO
>   values!  Here is an example program that will correctly use this "function.
"
>
>      function Get_Host_Name return String is
>
>         length   : INTEGER := 64;
>         hostname : STRING(1..Length);
>         result   : status_code;
>         counter  : integer;
>
>      begin
>         result := unix.gethostname(hostname(1)'address, length);
>         if result = Unix.OK then
>            for i in 1 .. length loop
>               if hostname (i) = ascii.nul then
>                  counter := i - 1;
>                  exit;
>               end if;
>            end loop;
>            return hostname(1 .. counter);
>         else
>            return "";
>         end if;
>      end Get_Host_Name;
>
>
>   That's right, after the call to gethostname, the variable hostname
>   has been modified to contain a string which is the hostname of the
>   machine that the program is running on...
>
>   Frankly, I'm offended!  This completely violates everything that I've
>   been taught about Ada functions! The actual parameters of a function
>   should not be modified.  A function should only return one value.
>
>   Wow, this is ugly! (Me thinks me smells a C programmer lurking
>                       behind that "function"...)

No need to get offended.  This function is obviously a direct
interface to the UNIX system call.  (I.e., no Ada code was written;
the function was declared with PRAGMA INTERFACE or the equivalent.) 

When you're interfacing to an external routine that returns a value
(presumably in a register), but also modifies its parameters, you
really have no choice except to declare a function that modifies its
parameters.  It's ugly, but it's really the only thing you can do.
(VAX Ada provides a neat variation of PRAGMA INTERFACE in which you
can declare it as an Ada *procedure*, and declare an OUT parameter to
hold the value returned in the register;  but I haven't seen this in
any other Ada.)

Yes, the Unix package could have hidden the implementation details in
the package body and provided a better-looking Ada interface.  But, I
suppose, there's an advantage to allowing the programmer direct access
to the UNIX system functions, without the overhead involved in
"Adaifying" it.

                                -- Adam

--
Standard disclaimers, with a few non-standard ones thrown in just to
confuse you.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1993-07-21 15:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-07-21 10:27 gethostname (Was: SunAda question) Karl A. Nyberg
  -- strict thread matches above, loose matches on Subject: below --
1993-07-21 14:56 David Emery
1993-07-21 15:26 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox