Usage of unlikely in RCU code

Manish Katiyar mkatiyar at gmail.com
Mon Aug 1 19:45:05 EDT 2011


> C absolutely guarantees that the second will NEVER be evaluated before
> the first. Otherwise, things like this:
>
> if ( ptr && ptr->field )
>
> could fail if ptr was NULL.

In your example yes. But is there a problem if the two conditions are
independent ? for eg..

foo() {
....
  a = 0;
  b = my_complex_function_call();
  if (b && a) {
      /* Do some non-trivial stuff */
  } else {
     printf("I'm an intelligent compiler\n");
  }
.....
}

Does C guarantee that even in this case it won't be reordered and not
optimized ?

-- 
Thanks -
Manish



More information about the Kernelnewbies mailing list