if(a() && b() && c() && d())
doSomething();
if(a())
if(b())
if(c())
if(d())
doSomething();
Is there "any" performance difference between these two?
For example, in a situation that a() turns 0, will it keep running b(), c() and d() in the first if statement? Or will it work same as the second nested if statement?
They're exactly identical.
To test this yourself, run
gcc -S test.c
(presuming that this is where you've put your source) and observe the contents oftest.s
.Here's how the nested-
if
approach compiles in gcc 4.8.1 with default options (annotated with comments):Here's how the
&&
approach compiles: