From mboxrd@z Thu Jan 1 00:00:00 1970 From: Erik Mouw To: alasdair@wildcat.demon.co.uk Cc: 97nv46@skola.kiruna.se, gcc@gcc.gnu.org Subject: Re: Volatile constants? Date: Wed, 29 Mar 2000 10:05:00 -0000 Message-id: <200003291805.UAA08004@duteinh.et.tudelft.nl> References: <14562.16912.888978.578471@wildcat.demon.co.uk> X-SW-Source: 2000-03/msg00764.html On Wed, 29 Mar 2000 18:49:04 +0100 (BST), Alasdair Baird wrote: > > > #define abs2(x) (x<0 ? -x : x) > > > > > > 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)) Yes, you're absolutely right. Erik -- In theory, practice and theory are the same, but in practice they are different -- Larry McVoy