Re: Macro challenge with variable arguments
Re: Macro challenge with variable arguments
- Subject: Re: Macro challenge with variable arguments
- From: Gwynne Raskind <email@hidden>
- Date: Thu, 01 Nov 2012 22:46:23 -0400
On Nov 1, 2012, at 10: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?
#if LOGGING
#define GCLOGOC(format, ...) GCLogObjCMethod(self, _cmd, __LINE__, NSStringFromClass([self class]), format, ## __VA_ARGS__)
#else
#define GCLOGOC(format, ...)
#endif
-- Gwynne Raskind
_______________________________________________
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