variable number of strings passed to function - how?

Gordon Cross crossgl at ingr.UUCP
Tue Nov 1 02:17:28 AEST 1988


In article <3533 at ihuxz.ATT.COM>, burris at ihuxz.ATT.COM (Burris) writes:
> In the C language arguments are placed on the stack in reverse order
> such that the first argument is the lowest index off of the stack pointer.
> This allows you to pass the first argument as a count of the number of
> following arguments.
> 
> Example:

  [ example deleted to save space ]

> 
> In both cases you set argp to the ADDRESS of the first string pointer
> on the stack. The CONTENTS of argp is the POINTER to the first string.
> Incrementing argp causes it to point to the second string pointer.
> 

The proper way to access variable numbers of arguments passed to a routine is
to use use <varargs.h>!!  Any assumptions about stack layout is just asking
for trouble (for example some compilers pass the first couple of args in
registers for efficiency reasons).  Check your manuals or any good "C"
programming book on how to use these macros....


Gordon Cross
Intergraph Corp.  Huntsville, AL



More information about the Comp.lang.c mailing list