Re: Macro challenge with variable arguments
Re: Macro challenge with variable arguments
- Subject: Re: Macro challenge with variable arguments
- From: Greg Parker <email@hidden>
- Date: Thu, 01 Nov 2012 19:34:38 -0700
On Nov 1, 2012, at 7:15 PM, Graham Cox <email@hidden> wrote:
> Hi all, I'm having trouble figuring this out.
>
> I have a logging function thus:
>
> void GCLogObjCMethod( id obj, SEL selector, NSUInteger lineNumber, NSString* tag, NSString* format, ... );
>
> I'd like to be able to wrap this using a macro that automatically supplies the object, selector, line number and 'tag' (which is usually the class name of the object) and leaves only the format and the variable arguments to be supplied. I haven't been able to come up with a way that works. Can it be done? i.e. what I want is a macro:
>
> GCLOGOC( @"this is a format string: %@, with any number of params: %@", paramA, paramB );
>
> and this expands to:
>
> GCLogObjCMethod( self, _cmd, __LINE__, NSStringFromClass([self class]), @"this is a format string: %@, with any number of params: %@", paramA, paramB );
>
> (or expands to nothing at all if logging has been turned off).
>
> How can I define the macro so it can handle the variable parameter list?
Look up __VA_ARGS__. I think you can build what you want that way.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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