Possible wrong-way example in gcc4-4-2 documentation of __builtin_expect

2011-12-19 Thread Jim Avera

Hello,

The online docs at
http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Other-Builtins.html
has a confusing (to me) example of __builtin_expect.  Could someone take 
a look at this?



  Since you are limited to integral expressions for exp, you should
  use constructions such as

  if (__builtin_expect (ptr != NULL, 1))
error ();


This seems backwards.The return value of __builtin_expect
is the first argument, namely (ptr != NULL), which presumably is true in 
the NON-error case.   The following example might be more helpful:


  if (__builtin_expect (ptr == NULL, 0))
error ();

Apologies if I'm not reading this correctly.

-Jim


Re: Possible wrong-way example in gcc4-4-2 documentation of __builtin_expect

2011-12-20 Thread Jim Avera
Ok, here is a patch which improves the example:

--- gcc/doc/extend.texi.ORIG    2011-12-20 17:35:32.236578828 -0800
+++ gcc/doc/extend.texi    2011-12-20 17:37:10.460583316 -0800
@@ -7932,7 +7932,7 @@
 
 @smallexample
 if (__builtin_expect (ptr != NULL, 1))
-  error ();
+  ptr->do_something();
 @end smallexample
 
 @noindent





From: Jonathan Wakely 
To: Segher Boessenkool  
Cc: james_av...@yahoo.com; gcc@gcc.gnu.org 
Sent: Tuesday, December 20, 2011 5:22 AM
Subject: Re: Possible wrong-way example in gcc4-4-2 documentation of 
__builtin_expect

On 20 December 2011 12:49, Segher Boessenkool wrote:
>
> The point of the example is that you cannot write
>
>          if (__builtin_expect (ptr, 1))
>            error ();
>
> so the "!= NULL" is important here.  But you are right that
> "error ()" is a bit unexpected; care to send a patch that changes
> it to e.g. "do_something ()"?

or even ptr->do_something() since that would depend on the value of ptr