Null pointer check elimination

richardcavell@mail.com richardcavell@mail.com
Wed Mar 9 05:23:00 GMT 2011


foo (char *x)
{
  char ret = *x;

  if (x)
    com();
  else
    bar();
  return ret;
}

>It is expected that the compiler will eliminate the pointer check with 
the option '-fdelete-null-pointer-checks' or with >the option -O2, -O3, 
or -Os.

Hang on, why would it eliminate the null pointer check, if the null 
pointer check is in the source code?  Are you assuming that the 
compiler knows for certain that x is non zero when it compiles the 
function?

Richard



More information about the Gcc-help mailing list