Chapter 35. #Definition
Difficulty: 4
What can and can't macros do? Not all compilers agree.
Demonstrate how to write a simple
max()
preprocessor macro that takes two arguments and evaluates to the one that is greater, using normal<
comparison. What are the usual pitfalls in writing such a macro?What can a preprocessor macro not create? Why not?
Solution
Common Macro Pitfalls
1. Demonstrate how to write a simple
max()
preprocessor macro that takes two arguments and evaluates to the one that is greater, using normal < comparison. What are the usual pitfalls in writing such a macro?
There are four major pitfalls, in addition to several further drawbacks. ...
Get More Exceptional C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.