This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Volatile constants?


 > > #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))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]