Re: Question regarding C code generation for a compound condition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Albert ARIBAUD <albert.aribaud@xxxxxxxxxxxx> 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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux