variable number of strings passed to function - how?
David Keppel
pardo at june.cs.washington.edu
Sat Oct 22 07:48:41 AEST 1988
>>[ I want to do string varargs ]
In article <3533 at ihuxz.ATT.COM> burris at ihuxz.ATT.COM (Burris) writes:
>[ In C, args are put on the stack in reverse order so the first arg
> is the lowest arg of the stack ponter ]
>[ example deleted ]
NO! DON'T TOUCH THAT... <sound of muffled explosion>
This is true on *some* machines, but is certainly false on other
machines. There are a couple reasons why. One is that the C language
doesn't define things to be done this way, so anybody who wants to
push right-to-left can do so as long as their compiler works. I'm not
sure that any modern compilers do this *currently*, but (a) there have
been in the past and (b) there probably will be again. Another good
reason why this isn't portable is that some machines have stacks that
grow *up* and some have stacks that grow *down*. Finally, there is no
guarantee that the arguments, even arguments of the same size, will be
in contiguous memory.
How to do this portably? Start with <varargs.h> or <stdargs.h>.
Then go read <14015 at mimsy.UUCP> (comp.lang.c, 16 Oct 1988).
;-D on ( "Every execution leaves you dangling..." ) Pardo
--
pardo at cs.washington.edu
{rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo
More information about the Comp.lang.c
mailing list