Q:

Objective-C: Expected ']' in macro

I have a fairly simple macro that I want to use to log messages. The Macro:
#define LogDebug(tag, fmt, ...) [MyLogger logDebug:[NSString stringWithFormat:fmt, ##__VA_ARGS__] \
function:NSStringFromSelector(_cmd) file:@__FILE__ line:__LINE__ tag:tag];

And I call it with:
LogDebug(@"tag", @"message");

The problem: at the beginning of @"tag" I get Expected ']', where Xcode points to the @ sign in the macro call (not the definition).
Important: if I remove the tag variable, everything works perfect:
#define LogDebug(fmt, ...) [MyLogger logDebug:[NSString stringWithFormat:fmt, ##__VA_ARGS__] \
function:NSStringFromSelector(_cmd) file:@__FILE__ line:__LINE__ tag:@"tag"];

and
LogDebug(@"message");

Any ideas?

A:

Macro parameter named tag interferes with logDebug's parameter named the same way – tag. Change the macro to:
#define LogDebug(tg, fmt, ...) [MyLogger logDebug:[NSString stringWithFormat:fmt, ##__VA_ARGS__] \
function:NSStringFromSelector(_cmd) file:@__FILE__ line:__LINE__ tag:tg];

(i.e. LogDebug(tag, fmt, ...) to LogDebug(tg, fmt, ...) and tag:tag to tag:tg).

