Null pointer check elimination
Michael N. Moran
mike@mnmoran.org
Mon Nov 14 21:02:00 GMT 2005
Gabriel Dos Reis wrote:
> "Michael N. Moran" <mike@mnmoran.org> writes:
>
> | And what is the meaning of code that does this:
> |
> | int foo(int& a)
> | {
> | int* b = &a;
> |
> | if(b ==0)
> | {
> | a();
> | }
> | else
> | {
> | b();
> | }
>
> According to the standard, the compiler can assume that the test is
> always false, therefore rewrite the if-else as an unconditional call to
> b(). GCC already does some null-pointer check deleting.
Wow. I'm sure there is sound reasoning for this ... but I can't
understand what that might be given a client module could intentionally
(if ill-adviseadly) simply invoke the function:
void bar()
{
int* z=0;
foo(*z);
}
In short this is "surprising" to clearly under-informed me.
--
Michael N. Moran (h) 770 516 7918
5009 Old Field Ct. (c) 678 521 5460
Kennesaw, GA, USA 30144 http://mnmoran.org
"So often times it happens, that we live our lives in chains
and we never even know we have the key."
The Eagles, "Already Gone"
The Beatles were wrong: 1 & 1 & 1 is 1
More information about the Java
mailing list