3 ms·
Another example to set aside for the next "So you think you are smarter than the compiler" person.
by jackmott 10y ago
Another example to set aside for the next "So you think you are smarter than the compiler" person.
- Pfhreak 10y agoIs that a helpful response to that person? Isn't that person (despite sounding like an ass) more or less right at any given time? Excepting environments where performance is critical (games comes to mind), shouldn't we bias toward improving the code for human readability?
- AstralStorm 10y agoTechnically, you could have some stronger keyword than inline in future C and C++ standards, akin to constexpr. For hard inlining always. For now, there are macros if an inline function does not work properly. Attributes to force inlining exist in some compilers, at least GCC and clang support those. Additionally marking the function as pure if applicable can help optimisers as well.
- AndrewGaspar 10y ago__forceinline in MSVC.
- niedzielski 10y agoThis is still a suggestion https://msdn.microsoft.com/en-us/library/bw1hbe6y.aspx https://msdn.microsoft.com/en-us/library/bw1hbe6y.aspx
- AstralStorm 10y agoThat usually works, with caveats as mentioned on page. (Security attributes and recursive calls that may remain recursive calls instead of stack utilising loops.) GCC and clang variants do not have this issue. MSVC is generally not really known for high performance of generated code, which is partly why newest versions support a clang backend.
- enqk 10y agoMSVC's latest versions support a clang frontend w/ microsoft's code generation as backend. Are you referring to something else?
- zyxley 10y agoYou may find the Nim language to be interesting. The entire language is processed as an AST, so you can do a lot of magic stuff like write normal functions, functions with forced inlining, and AST-transforming macros all in the same syntax and all processed in one pass at compile time. http://nim-lang.org http://nim-lang.org
- DannyBee 10y agoconstexpr functions exist, and they are also inline :)