When do compilers inline C++ code?

前端 未结 11 1172
孤独总比滥情好
孤独总比滥情好 2020-11-29 08:07

In C++, do methods only get inlined if they are explicitly declared inline (or defined in a header file), or are compilers allowed to inline methods as they see

11条回答
  •  情深已故
    2020-11-29 08:55

    Text from IBM information Center,

    Using the inline specifier is only a suggestion to the compiler that an inline expansion can be performed; the compiler is free to ignore the suggestion.

    C Language Any function, with the exception of main, can be declared or defined as inline with the inline function specifier. Static local variables are not allowed to be defined within the body of an inline function.

    C++ functions implemented inside of a class declaration are automatically defined inline. Regular C++ functions and member functions declared outside of a class declaration, with the exception of main, can be declared or defined as inline with the inline function specifier. Static locals and string literals defined within the body of an inline function are treated as the same object across translation units;

提交回复
热议问题