home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!spool.mu.edu!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
- From: torek@horse.ee.lbl.gov (Chris Torek)
- Newsgroups: comp.lang.c
- Subject: Re: Calling convention: C vs PASCAL
- Date: 12 Dec 1992 18:34:11 GMT
- Organization: Lawrence Berkeley Laboratory, Berkeley CA
- Lines: 45
- Message-ID: <27947@dog.ee.lbl.gov>
- References: <1992Dec11.225756.26780@eng.ufl.edu> <1992Dec12.171137.17577@taumet.com>
- NNTP-Posting-Host: 128.3.112.15
-
- In article <1992Dec12.171137.17577@taumet.com> steve@taumet.com
- (Steve Clamage) writes:
- >Neither the C nor Pascal language specifications require the parameter
- >ordering mentioned, but they are common implementation techniques.
-
- (For that matter, these days it is common to pass the first two-to-six
- parameters in registers, except on the 80x86 where the registers are
- far too precious to be used this way.)
-
- >C allows a function to be called with more parameters than were declared
- >for it.
-
- In ANSI C, this is only true of `, ...' functions, such as printf().
- Moreover, these must be declared in advance as such. This gives IBM PC
- C compilers license to use the variant of `return' that adds to the
- stack pointer, except when calling or returning from one of these
- `special' functions.
-
- In particular, this means that:
-
- /* incorrect version of `hello world' */
- int main(void) { printf("Hello world\n"); return 0; }
-
- may well malfunction on an IBM PC. To correct it, you *must* add at
- least one of the following two lines:
-
- #include <stdio.h>
- int printf(char *, ...);
-
- It is then guaranteed to work on any ANSI-conformant hosted system,
- including all IBM PC C compilers. Without the `advance notice' that
- printf() is a `special' function, it need not work properly.
-
- Of course, if one happened to go to your nearby mall and buy an IBM PC
- C compiler, and it failed to compile and run the incorrect version, one
- would be tempted to advise others against buying this particular
- compiler---not necessarily believing that it is `wrong' or `buggy', but
- perhaps only because one knows just how much old, nonconformant code
- exists. In other words, market forces pretty much guarantee that *your*
- IBM PC C compiler by default uses the so-called `slow method' (which,
- as Steve pointed out, need not actually be slower: there is no reason
- that one *must* clear the stack after every function call).
- --
- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
- Berkeley, CA Domain: torek@ee.lbl.gov
-