Re: NSLog and va_list
Re: NSLog and va_list
- Subject: Re: NSLog and va_list
- From: Bill Bumgarner <email@hidden>
- Date: Thu, 17 Jun 2010 09:29:46 -0700
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 (email@hidden)
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:
This email sent to email@hidden