Menu

inline functions

Fraser
2023-10-06
2023-10-07
  • Fraser

    Fraser - 2023-10-06

    Does cppcheck issue a warning for small functions that are not declared inline? I can't remember ever seeing one. It is an optimisation that has existed for a long time but is easily neglected. Many functions now are declared with constexpr which makes an implicit inline declaration from C++11.

     
  • Daniel Marjamäki

    There is no warning to declare a function inline.

    Well, personally I am a bit skeptic about it. Cppcheck does not have detailed knowledge about the compiler and hardware. Probably the compiler inlines small functions anyway if that makes sense.

     
  • Fraser

    Fraser - 2023-10-07

    To use inline on small functions is recommended by C++ Core Guidelines F5. It says inline isn't required for function templates but unless they are defined within a class definition they are not inplicitly declared inline.

     
  • Daniel Marjamäki

    alright. if we implement a c++ core guidelines ruleset it certainly makes sense to implement this. It sounds like a good idea to implement that ruleset.

     

    Last edit: Daniel Marjamäki 2023-10-07
  • Fraser

    Fraser - 2023-10-07

    I can't see a negative side to it other than too much inlining. Someone thought it was worthwhile making constexpr functions implicitly declared inline.

     
  • Fraser

    Fraser - 2023-10-07

    I find that many potentialy inlined functions are defined in a .cpp file and called from another translation unit.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.