Question regarding C code generation for a compound condition
Ian Lance Taylor
iant@google.com
Tue Jun 7 17:37:00 GMT 2011
Albert ARIBAUD <albert.aribaud@motorola.com> writes:
> Granted, the way the condition is written is not valid, as the
> evaluation will be done left to right, causing a dereference of g
> before testing it against NULL -- the right order should be "(g==NULL)
> || (g->a==0)", with short-circuit ensuring g->a is only evaluated if g
> != NULL.
Once the compiler successfully evaluates g->a == 0, it knows that g !=
NULL. If g == NULL, then the evaluation of g->a will crash. So there
is no need for the compiler to test g == NULL, since it will never be
true. This is a feature, not a bug. See -fdelete-null-pointer-checks.
Ian
More information about the Gcc-help
mailing list