Can I selectively (force) inline a function?

后端 未结 6 532
执念已碎
执念已碎 2020-12-28 13:46

In the book Clean Code (and a couple of others I have come across and read) it is suggested to keep the functions small and break them up if they become large. It also sugge

6条回答
  •  孤城傲影
    2020-12-28 14:20

    There is nothing that prevents you to put inline in a static function in a .cpp file.

    Some compilers have the option to force an inline function, see e.g. the GCC attribute((always_inline)) and a ton of options to fine tune the inlining optimizations (see -minline-* parameters).

    My recommendation is to use inline or even better static inline wherever you see fit, and let the compiler decide. They usually do it pretty well.

提交回复
热议问题