Just as the question, What's the advantage of using macro in c? What do you think is the advantage?
Asked
Active
Viewed 1,681 times
3
-
1possible duplicate of [Why would a developer use a macro?](http://stackoverflow.com/questions/1760028/why-would-a-developer-use-a-macro) – Matthew Flaschen Mar 15 '11 at 04:23
-
hmmm I guess what I am trying to ask is that what's the advantage in terms of compiler optimization? what's the advantage in terms of debugging etc.. the link to that question isn't what i am looking for – David Gao Mar 15 '11 at 05:16
-
it's just i want to see what people are using macro for... more like people's personal opinion, not rly a question... – David Gao Mar 15 '11 at 05:17
-
There are all the basic reasons, but where I really appreciate the preprocessor is using it as a code-generator, as in [this DSL](http://stackoverflow.com/questions/371898/how-does-differential-execution-work). – Mike Dunlavey Mar 15 '11 at 16:07
1 Answers
4
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.

paxdiablo
- 854,327
- 234
- 1,573
- 1,953