4 ms·
> don’t use it for inline functions That's a myth afaik. Is there any standard way besides macros to really ensure the code will be inlined? In particular, the
by qb45 9y ago
> don’t use it for inline functions
That's a myth afaik. Is there any standard way besides macros to really ensure the code will be inlined? In particular, the suggestively named inline keyword just doesn't work like that.
- foonathan 9y agoThere are attributes like `[[gnu::always_inline]]` for GCC and clang.
- qb45 9y agoYes, but they aren't portable. You can work around this using per-compiler macros, which I guess is another reason why CPP is to stay.
- ChrisFoster 9y agoThe preprocessor is a workable but somewhat poor tool for inlining code due to several reasons (no overloading, no sensible macro scoping, template argument lists clash with macro argument lists, etc). However, it's quite a reasonable tool for helping to force inline code in a nonstandard but somewhat portable way. See, for example, EIGEN_ALWAYS_INLINE at https://eigen.tuxfamily.org/dox/Macros_8h_source.html https://eigen.tuxfamily.org/dox/Macros_8h_source.html
- smitherfield 9y agoSticking with stuff that's in the standard, "constexpr" is, among other things, a more strongly-suggested "inline". Also, inlining is likely if you compile with -02/-03 and declare the function with internal visibility (in an anonymous namespace or with "static", although the latter is deprecated in favor of the former in C++).