On Jun 17, 2010, at 5:37 AM, Alexander Spohr wrote:

> But I think you want to know what the va_list contains.
> Then you just loop over it.
> "man stdarg" will help.
> 
> Example:
>           void foo(char *fmt, ...)
>           {
>                   va_list ap;
>                   int d;
>                   char c, *p, *s;
> 
>                   va_start(ap, fmt);
>                   while (*fmt)
>                           switch(*fmt++) {
>                           case 's':                       /* string */
>                                   s = va_arg(ap, char *);
>                                   printf("string %s\n", s);
>                                   break;
>                           case 'd':                       /* int */
>                                   d = va_arg(ap, int);
>                                   printf("int %d\n", d);
>                                   break;
>                           case 'c':                       /* char */
>                                   c = va_arg(ap, char);
>                                   printf("char %c\n", c);
>                                   break;
>                           }
>                   va_end(ap);
>           }

That won't work in the general case.  In the above, you have arbitrarily 
created a function and passed a format string that contains an also-arbitrary 
mapping of character -> type.

As someone else said, you cannot generically decode a va_list because there is 
no type information available.   When there is a format string, the rules are 
API specific and you are going to have to decode the entire set of possible 
combinations in the format string which, for NSLog and the like, can be quite 
complex.

b.bum

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to