Volatile constants?

Alasdair Baird alasdair@wildcat.demon.co.uk
Wed Mar 29 09:53:00 GMT 2000


 > > #define abs2(x) (x<0 ? -x : x)
 > 
 > <nitpick>
 > You should define this as:
 > 
 >   #define abs2(x) ((x) < 0 ? (-x) : (x))
 > 
 > Rationale: see what happens with your version if you use abs2(2 - 3). The
 > extra parentesis enforce the correct operator precedence.

I think that you might find the following to actually be correct though:

   #define abs2(x) ((x) < 0 ? -(x) : (x))


More information about the Gcc mailing list