3 ms·
Outputting the pre-processor result is not that helpful, you're still stuck with deciphering things. macro expansion is useless, again, for same reason you can
by emcrazyone 11y ago
Outputting the pre-processor result is not that helpful, you're still stuck with deciphering things.
macro expansion is useless, again, for same reason you can't marry it to actual code. If you can do this now, would be at most curious (not interested) as it's evil to begin with.
A production build in the embedded world, typically means you don't have symbols. Often they are stripped to save space and unless you have a USB stick or something you carry with you with map files, you're still toast.
And there are a whole host of other reasons why they are just pure evil:
1. Global scope only.
2. Unexpected results rather than error messages - ISO25259 won't even allow you to do this if that tells you anything.
3. Can't use sizeof
4. no type checking. Every compiler I've used, including GCC, won't warn about if an int is compared to unsigned.
5. can't take the address
6. worst, substituted value need not even be legal in the context the #define is created because it is evaluated at each point it is referenced allowing to another evil problem of being able to reference objects that are not declared yet.
I could go no... and I haven't even touched on strings yet.
with so many problems, I have a hard time justifying or championing their use.
- kllrnohj 11y agoThe vast, vast majority of your "evil" list is either just wrong or unrelated. I don't think you really know what macros are or how/when to use them.
- kstenerud 11y ago> 1. Global scope only. So are functions, by that rationale. If you want to control scope of variables, pass in macro parameters. > 2. Unexpected results rather than error messages When have min() or max() produced unexpected results rather than error messages? They're macros, you know. > Every compiler I've used, including GCC, won't warn about if an int is compared to unsigned. -Wconversion > 5. can't take the address You can't take the address of a struct definition or a typedef, either. Macros are not replacements for functions; they're code generators. > 6. worst, substituted value need not even be legal in the context the #define is created because it is evaluated at each point it is referenced allowing to another evil problem of being able to reference objects that are not declared yet. I don't even... You do know that, following the preprocessing phase, the compiler actually checks the generated code for legality, right? And since when is forward referencing evil?