Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Another example to set aside for the next "So you think you are smarter than the compiler" person.


Is 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?


Technically, 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.


You 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


__forceinline in MSVC.



That 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.


MSVC's latest versions support a clang frontend w/ microsoft's code generation as backend. Are you referring to something else?


constexpr functions exist, and they are also inline :)




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: