CM Lin
CM Lin

Reputation: 13

Usage of C definition

I have a question about the definition in c code as bellow.

#define DESC(x) 1

#if DESC("abc cdef")
.... some implementation or declaration
#endif

What exactly does the macro DESC("abc cdef") mean? Does it stand for a sub module? It this is true, where can I refer to the information about it?

Thank you for go through this question.

Upvotes: 1

Views: 148

Answers (2)

jackw11111
jackw11111

Reputation: 1547

This is a function-like macro, which takes in x as a parameter and returns 1.

Upvotes: 1

jamesdlin
jamesdlin

Reputation: 90015

DESC(x) is a function-like preprocessor macro. In your case, it ignores its input and always replaces it with an integer literal 1.

I don't know for certain why it's being used this way, but I suspect the author wanted:

  1. To add descriptions to sections of code.
  2. To clearly delimit what sections those descriptions apply to (via #if ... #endif).

(Most people would use comments for #1, but with just comments sometimes #2 is unclear.)

Upvotes: 3

Related Questions