Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Comparing a function pointer to a value that is not a null function pointer of the same type shall be diagnosed because this typically indicates programmer error and can result in unexpected behavior. Implicit comparisons shall be diagnosed as well.

Noncompliant Code Example

In this noncompliant code example, the function pointers getuid and geteuid are compared to 0.

...

Code Block
bgColor#ccccff
/* First the options that are only allowed for root */
if (getuid() == 0 || geteuid() != 0) {
  /* ... */
}

Compliant Code Example

A function pointer can be compared to a null function pointer of the same type.

...

Code Block
bgColor#FFcccc
int do_xyz(void); 
 
if (do_xyz) { 
  /* handle error */ 
} 

Compliant Solution

In this compliant solution, the function do_xyz() is invoked and the return value is compared to 0.

...