--- Roland Smith <[EMAIL PROTECTED]> wrote: > 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. > Infact, I have implemented it in this way. I was wondering if there is a better way. The issue I see is, if someone forget to close the arg list with NULL pointer, it crashes.
> > 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) > This is interesting. Who set the num? The compiler or the user. If it is the user, its no better than above NULL pointer method. If this is possible, my problem is solved: f(str1, str2, str3, ..., strN) is at compile time expands to _f(int num, str1, str2, str3, ..., strN). The num is set automatically by the compiler by counting the args. Is this possible? Unga ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ _______________________________________________ firstname.lastname@example.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"