J
Jordan Abel
Keith said:Kunal said:Thanks for all your responses.
To what? Please read <http://cfaj.freeshell.org/google/>.
[...]
I am still not clear why would the compiler generate a branch condition
if only a boolean expression is to be solved.
As in
c += (a > B);
as opposed to the equivalent
if (a > B)
c++;
}
If you're familiar with the assembly language of whatever CPU you
happen to be using, try writing your own code to implement the first
assignment. If the CPU provides an instruction that compares two
values and stores a 0 or 1 depending on the result, the compiler is
likely to use it. If not, a conditional branch may well be the best
way to accomplish it, even if it might cause a pipeline stall.
If the CPU has an instruction that could do the job efficiently and
it's not using it (when you specify the maximum level of
optimization), you might consider complaining to the compiler vendor.
It's really not a C language issue. As long as the generated code
gets the right answer, the C standard is happy.
Actually, does the C standard now require a true expression result to
be 1?
(sorry, but I still think of C in terms of the original K&R, where 0 is
false and anything else is true. And I've done enough assembler
programming to know the compare doesn't simply result in a 1 in a
usable register.)
the "as if" rule will let you weasel out of it in most cases for a real
implementation, but if you assign the result of a relational/equality
comparison expression to an integer variable, it must be 1 for true, 0
for false.