Re:The most stupid C bug ever
by exDM69 on Wednesday August 24, 2011 @06:22AM
(#2920181)
"That has a performance impact on all platforms: the direct call to tmpfile() is now an indirect, which defeats optimization, and well, everything."
This couldn't be any more wrong. First of all, even if there were a performance impact, it would be meaningless compared to the time it takes to perform the system calls required for tmpfile().
Second, the compiler will inline the function call if it can. You can use a regular "inline" function and if you're not convinced it's good enough, then use __attribute__(force_inline) or equivalent. Even if the damn function is not an inline function, it will get inlined if it's in the same translation unit as where it is called (look at the asm output of gcc -O3). In the (not so far) future we'll be able to enjoy link time optimizations and don't have to care about translation units w.r.t. inlining optimizations.
Re:The most stupid C bug ever
by msftguy on Wednesday August 24, 2011 @11:13AM
(#2921000)
Even without inlining, it will be subject to tail call elimination with any sane compiler: my_tmpfile will just branch to _imp_tmpfile instead or returning.
This couldn't be any more wrong. First of all, even if there were a performance impact, it would be meaningless compared to the time it takes to perform the system calls required for tmpfile().
Second, the compiler will inline the function call if it can. You can use a regular "inline" function and if you're not convinced it's good enough, then use __attribute__(force_inline) or equivalent. Even if the damn function is not an inline function, it will get inlined if it's in the same translation unit as where it is called (look at the asm output of gcc -O3). In the (not so far) future we'll be able to enjoy link time optimizations and don't have to care about translation units w.r.t. inlining optimizations.