1

I have define VLog like this:

#define VLog(s, ...)  NSLog(@"%@", [NSString stringWithFormat:(s), ##__VA_ARGS__])

I know VLog(@"hello,%d%@", 1, @"a"); __VA_ARGS__ is replaced with 1, @"a".

Whereas, VLog(@"hello"); __VA_ARGS__ is replaced with what?

and if I define VLog like this:

//delete ##
#define VLog(s, ...)  NSLog(@"%@", [NSString stringWithFormat:(s), ##__VA_ARGS__])`

VLog(@"123"); is pointed out error.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
simalone
  • 2,768
  • 1
  • 15
  • 20

1 Answers1

0

In case of zero variable arguments, __VA_ARGS__ is replaced with nothing. ## is special in that it removes preceding , in that case, so compiler won't complain "expression needed after comma". A macro defined without ##, i.e. [NSString stringWithFormat:(s), __VA_ARGS__] will require additional arguments.

user3125367
  • 2,920
  • 1
  • 17
  • 17