4 ms·
In most cases I would wager I have a better idea of where I want the optimizations to be applied in code than the compiler does. Macros, unlike inline function
by maximilianburke 11y ago
In most cases I would wager I have a better idea of where I want the optimizations to be applied in code than the compiler does.
Macros, unlike inline functions, will always give you the result you are looking for. You don't have to worry about things like regressed performance because a new compiler versions has tweaked inlining heuristics.
The use of "inline" is diminished in much real world C++ too. Because it's used liberally in user code and added implicitly to member functions defined in a class definition there already is much code that is inline-worthy. There is no way in C++ to say "I explicitly want THIS code to be inlined HERE", unless you use a macro.
In theory you can get benefits out of using PGO but PGO is also non-standard, not available on all compilers, and a pain to setup.
Inline functions will also never be able to replace the diagnostics available with the preprocessor; being able to extract the line and file for things like assertions is something you can't do with inline functions.
Inline functions have their use, but so do preprocessor pseudo-function macros, and saying that there isn't a valid use for these macros is claptrap that I'd attribute to someone who hasn't shipped performance sensitive code in C or C++ before.
- chrisseaton 11y ago> saying that there isn't a valid use for these macros Nobody in this thread has said that.
- maxlybbert 11y agoI recognize that there is some use for macros, but the valid cases have been getting smaller over time.