开发者

Question about #define statement in Objective-C project

I'm not experienced in C, so I'm not comfortable with this statem开发者_运维问答ent in this C / objective-C project.

#define CBLog(...) NSLog(@"%s [%ld]: %@", basename(__FILE__), __LINE__, [NSString stringWithFormat:__VA_ARGS__])

Questions:

  1. the 3 dots (...) are used to indicate CBLog() is a method with parameters ? What do they mean ?

  2. %ld stands for line format ? what's the d in %ld for ?

  3. FILE , LINE and VA_ARGS are default replacement tokens for the C debugger ?

thanks


The ... means the macro accepts any number of arguments.

%ld is a string formatter meaning 'long decimal', where decimal really means integer.

__FILE__ expands to the current file name

__LINE__ expands to the current line number

__VA_ARGS__ expands to the arguments passed to the macro.

The debugger has nothing to do with it. All of this is the preprocessor, except %ld which is string formatting.


  1. ... means that any number of arguments can be given.
  2. %ld means signed long, though it's a bit strange as I've never seen signed line numbers.
  3. __FILE__ is the current source file's filename. __LINE__ is the current line number. __VA_ARGS__ are the arguments given to the macro.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜