This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Null pointer check elimination


"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.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]