1

Assuming I have a macro like this

#define A(x) NSLog(@"%@", x)

how can I call it and format the string in the macro argument like this

A([NSString stringWithFormat:@"Random string with number %d", 5]);

I am getting error too many arguments provided to function-like macro invocation and the error marker points to the comma, which makes sense, since I assume that is there the preprocessor splits the arguments, since it does not know the context that it is a selector call. Is it even possible to do this?

Rudolfs Bundulis
  • 11,636
  • 6
  • 33
  • 71

1 Answers1

2

As the linked question's answer says, the solution lies in using an extra pair of paranthese at the call site:

A(([NSString stringWithFormat:@"Random string with number %d", 5]));

works.

Gereon
  • 17,258
  • 4
  • 42
  • 73