Are C++ class methods defined in the header always inlined?

前端 未结 6 685
醉酒成梦
醉酒成梦 2021-01-12 01:05

Edit: I\'ve restored the original title but really what I should have asked was this: \'How do C++ linkers handle class methods which have be

6条回答
  •  离开以前
    2021-01-12 01:28

    Nothing is always inlined (unless your compiler has an attribute or private keyword to force it to do so...at which point you're writing $(COMPILER)-flavored C++ rather than standard C++). Very long functions, recursive functions, and a few other things generally aren't inlined.

    The compiler can choose not to inline stuff if it determines that doing so will degrade performance, unreasonably increase the object file's size, or make things work incorrectly. Or if it's optimizing for size instead of speed. Or if you ask it not to. Or if it doesn't like your shirt. Or if it's feeling lazy today, cause it compiled too much last night. Or for any other reason. Or for no reason at all.

提交回复
热议问题