3 ms·
The macro isn't the complicated part in the OP (`e` just gets substituted with whatever the argument is). The definition the macro generates is (for most cases
by colanderman 10y ago
The macro isn't the complicated part in the OP (`e` just gets substituted with whatever the argument is). The definition the macro generates is (for most cases, needlessly) complicated, but that has nothing to do with macros or the preprocessor.
The general rules of macros are:
1. Don't use them; prefer static functions.
2. Use them as symbolic constants only.
3. Use parameterized macros only when you must use # or ## (i.e., for code abstraction), and then use them sparingly.
4. If you really insist, wrap every use of the arguments in parentheses, and be careful not to write the name of an argument somewhere where you don't mean it.
You'll get pretty far knowing next to nothing about macros (e.g. expansion phases and tokenization rules) by following the above rules.