Will it execute everywhere ?

Stephen Clamage steve at taumet.com
Sun Jul 29 08:07:03 AEST 1990


csp at gtenmc.UUCP (Charudutta S. Palkar) writes:


>	This is to avoid the usage of varargs. The only restriction
>	is to pass number of arguments as the first parameter.
>	Will this piece of code execute irrespective of the order
>	in which the parameters are pushed on the stack ie. right
>	to left or left to right?
[ included code which scanned up the stack from first parameter ]

1.  Some systems do not necessarily pass parameters on a stack.  To
get variable parameter lists, you need help from the compiler.

2.  On some systems the stack grows up, on some it grows down.  Some
systems push parameters left-to-right, others right-to-left.  Combining
these two unknowns, you might scan up OR down from the first parameter
to find the rest.

3.  Some systems use differing alignments when pushing arguments on the
stack, and a simple scan will fail.

Some Unix systems added <varargs.h>, and ANSI standardized on <stdarg.h>,
so that you could write code that would always work, no matter how the
compiler or implementation changed.  If you can't or won't use these
aids, you will have to check each release of each compiler and each
runtime system to see whether the code you write will work.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list