aneuryzm
aneuryzm

Reputation: 64834

Question about #define statement in Objective-C project

I'm not experienced in C, so I'm not comfortable with this statement 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

Upvotes: 3

Views: 285

Answers (2)

user142019
user142019

Reputation:

  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.

Upvotes: 2

Ned Batchelder
Ned Batchelder

Reputation: 375474

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.

Upvotes: 5

Related Questions