comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: GNAT parameter passing, C-style?
Date: Mon, 05 Jan 2004 21:06:00 GMT
Date: 2004-01-05T21:06:00+00:00	[thread overview]
Message-ID: <lnd69ym7ga.fsf@nuthaus.mib.org> (raw)
In-Reply-To: 4iBIb.8173$qS3.498@nwrdny03.gnilink.net

"Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> writes:
[...]
> In vanilla (i.e. original K&R) C, there are no argument lists in function
> declarations. For that matter, vanilla C does NOT even require functions
> declarations. If an undeclared function is called in vanilla C, the
> unconverted argument list is assumed to be OK, the calling convention is
> assumed to be C, and it is assumed that the function returns an int.

The term "vanilla" implies that the original K&R C is the default
version of the language.  It isn't.  The 1990 ISO C standard is almost
universally implemented these days (though not always perfectly); it's
difficult to find a C compiler that doesn't implement prototypes, for
example.  (My ancient SunOS 4.1.3 box has a K&R C compiler, but I
rarely use it, since I've also installed gcc.)

> ANSI C depreciates this loose approach to functions. ANSI C strongly
> encourages the full declaration of all functions used, including argument
> lists. For compatability, however, ANSI C accepts function declarations with
> no argument lists (e.g. "double sin();"), as well as the calling of
> undeclared functions. Since there is no requirement that the user will
> declare a function's argument list (or the function for that matter), a C
> compiler may not be able to tell whether a function accepts a variable
> argument list or not. For that reason, C compilers have to assume the C
> calling convention, unless the user indicates via declaration or command
> line options.

Nitpick: it's "deprecates".

The latest ISO C standard, C99, requires full declarations for
functions, but it's not widely implemented yet; so far, it's not
catching on as quickly as C90 did.  (C90, the 1990 ISO C standard, is
essentially identical to C89, the 1989 ANSI C standard.)

If a function takes a variable number of arguments, any call to that
function without a prototype in scope invokes undefined behavior.
That means the implementation isn't required to diagnose the problem,
but the standard places no constraints on the program's behavior.
(Over in comp.lang.c, we traditionally say that it's allowed to make
demons fly out your nose.)

One of the biggest advantages of Ada over C is that it has far fewer
instances of undefined behavior.  An advantage of C over Ada is that
it uses the straightforward term "undefined behavior" rather than
"erroneous execution".

> Every C compiler that I have worked with uses the C calling convention by
> default when compiling C (as opposed to C++) code.
[...]

There is no such thing as "the C calling convention", though some
implementations may (misleadingly) use the phrase to refer to the
default calling convention used by a particular C compiler on a
particular system.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"



  parent reply	other threads:[~2004-01-05 21:06 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-26 10:37 GNAT parameter passing, C-style? Luke A. Guest
2003-12-26 14:20 ` Marin David Condic
2003-12-26 14:51   ` Hyman Rosen
2003-12-26 15:07     ` Marin David Condic
2003-12-26 15:39       ` Luke A. Guest
2003-12-26 17:03         ` Hyman Rosen
2003-12-26 17:08           ` Luke A. Guest
2003-12-26 17:27             ` Luke A. Guest
2003-12-26 18:21               ` Frank J. Lhota
2003-12-26 19:06                 ` Frank J. Lhota
2003-12-31 10:23                 ` Keith Thompson
2003-12-31 14:45                   ` Frank J. Lhota
2003-12-31 15:05                     ` Hyman Rosen
2003-12-31 16:30                       ` Frank J. Lhota
2003-12-31 17:24                         ` Hyman Rosen
2003-12-31 19:05                           ` Frank J. Lhota
2003-12-31 19:38                             ` Hyman Rosen
2003-12-31 20:47                               ` Frank J. Lhota
2003-12-31 21:35                                 ` Hyman Rosen
2004-01-01  2:50                                   ` Frank J. Lhota
2004-01-01  5:20                                     ` Luke A. Guest
2004-01-01 16:06                                       ` Hyman Rosen
2004-01-01 16:32                                         ` Frank J. Lhota
2004-01-01 16:43                                           ` Hyman Rosen
2004-01-02  0:24                                             ` Frank J. Lhota
2004-01-02  4:09                                               ` Hyman Rosen
2004-01-02 13:29                                                 ` Frank J. Lhota
2004-01-01  5:17                                   ` Luke A. Guest
2004-01-01  5:09                                 ` Luke A. Guest
2004-01-02  1:17                                   ` tmoran
2004-01-01 17:18                                 ` Jano
2004-01-02  0:25                                   ` Frank J. Lhota
2004-01-07  6:37                         ` Dave Thompson
2004-01-01  3:38                       ` Marin David Condic
2004-01-01  5:28                         ` Luke A. Guest
2004-01-01 14:17                           ` Marin David Condic
2004-01-01 16:20                             ` Jeff C,
2004-01-02 13:47                               ` Marin David Condic
2004-01-05 21:06                     ` Keith Thompson [this message]
2004-01-06  3:42                       ` Robert I. Eachus
2004-01-06 20:54                         ` Keith Thompson
2004-01-06 23:45                           ` Robert I. Eachus
2004-01-06 13:46                       ` Frank J. Lhota
2003-12-27 14:22             ` Marin David Condic
2003-12-26 17:10         ` Martin Krischik
2003-12-26 19:04           ` Frank J. Lhota
2003-12-26 18:01   ` Georg Bauhaus
replies disabled

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