What's the advantage of using macro in c? [closed]
Just as the question, What's the advantage of using macro in c? What do you think is the advantage?
Nowadays, I only use macros for very simple flags (conditional compilation and such).
The efficiency of inline expansion has been taken up by the inline
keyword, constants can be done better with const
, and lists of values can be done better with enum
.
Those latter two have the advantage that the symbols are available to the debugger. With preprocessor values, these almost certainly turn into hard-coded values before the compiler proper sees them. Constant variables and enumerations keep the identifier information available, making the debug process a lot easier.
精彩评论