On Sun, May 04, 2008 at 12:40:43AM -0700, Unga wrote: > Hi all > > I need to implement a variable argument function in C. > The number of args are not known but the type is > known, all are strings. > > Unfortunately va_arg() [stdarg(3)] does not return > NULL or any other suitable value after processing the > arg list, it just simply crashes once the arg list is > exhausted.
It is _your_ task to properly close the argument list. E.g. by supplying a NULL pointer as the last argument. > It seems there is no way to know the number of args > inside the called function. Not with stdarg. > How do you guys implement variable arg function such > as f(str1, str2, str3, ..., strN)? you could use the same format as main: int foo(int num, char **args) Roland -- R.F.Smith http://www.xs4all.nl/~rsmith/ [plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated] pgp: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)
Description: PGP signature