Will the c++ compiler optimize away unused return value?

后端 未结 7 487
灰色年华
灰色年华 2021-01-18 19:24

If I have a function that returns an object, but this return value is never used by the caller, will the compiler optimize away the copy? (Possibly an always/sometimes/never

7条回答
  •  情话喂你
    2021-01-18 20:03

    The linker can take care of this sort of thing, even if the original caller and called are in different compilation units.

    If you have a good reason to be concerned about the CPU load dedicated to a method call (premature optimization is the root of all evil,) you might consider the many inlining options available to you, including (gasp!) a macro.

    Do you REALLY need to optimize at this level?

提交回复
热议问题