variable number of strings passed to function - how?

Sleaze Hack joshua at athertn.Atherton.COM
Tue Oct 25 04:26:49 AEST 1988


In article <1962 at lznh.UUCP> ariel at lznh.UUCP (<10000>Ariel Aloni) writes:
>
>[Lots deleted, but we're talking about the order arguments get pushed on
> the stack during a C function call.]
>
>This is a convention adopted by most compilers, it was never promised
>by K&R (maybe somebody can enlighten us on ANSI-C ?).
>

Not only does ANSI not promise us the order of arguments pushed on the stack,
it does not promise us that this order will always be the same within a
program!  For example, the Tandem compiler (version C00 and later) pushes
arguments left to right, unless the function takes a variable number of
arguments, when it pushes them right to left.  The standard says it is OK
to force vararg functions to be prototyped before use, and Tandem requires
this, so that it can always tell the difference between an "normal" function
and a "vargargs" function.  Obviously, having two different, and incompatible,
stack frames in use in the same program can cause a lot of problems if you
are not very careful.  Think of all the problems that pointers to functions
could cause!

Tandem did this so that most function calls would be compatible with their
other languages (PASCAL, TAL, etc.) which push arguments left to right.
Tandem claims that this compiler is as ANSI conformant as possible
(realizing that the standard is not a Standard yet).

Summary on the portable use of variable arguments to a C function:
use stdargs or varargs, or somewhere you will die.

Josh
--------                Quote: "If you haven't ported your program, it's not
Addresses:                      a portable program.  No exceptions."  
joshua at atherton.com OR         
sun!athertn!joshua  OR                 
{backbone}!{decwrl!hpda}!athertn!joshua  work:(408)734-9822 home:(415)968-3718



More information about the Comp.lang.c mailing list