我对VLog的定义如下:
#define VLog(s, ...) NSLog(@"%@", [NSString stringWithFormat:(s), ##__VA_ARGS__])我知道VLog(@"hello,%d%@", 1, @"a"); __VA_ARGS__被1,@"a“取代。
然而,VLog(@"hello"); __VA_ARGS__被替换为什么?
如果我这样定义VLog:
//delete ##
#define VLog(s, ...) NSLog(@"%@", [NSString stringWithFormat:(s), ##__VA_ARGS__])`指出了VLog(@"123");的误差。
发布于 2014-02-19 08:03:46
在零变量参数的情况下,__VA_ARGS__将被替换为nothing。##很特殊,因为在这种情况下它删除了前面的,,所以编译器不会抱怨“逗号后面需要的表达式”。没有##定义的宏,即[NSString stringWithFormat:(s), __VA_ARGS__]需要额外的参数。
https://stackoverflow.com/questions/21873616
复制相似问题