Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!bcm!dimacs.rutgers.edu!seismo!uunet!mcsun!ukc!icdoc!inmos!nathan@elberton.inmos.co.uk From: nathan@elberton.inmos.co.uk (Nathan Sidwell) Newsgroups: comp.lang.c Subject: Re: Is #define THING -10 completely safe? Message-ID: <12924@wraxall.inmos.co.uk> Date: 31 Jan 91 12:59:10 GMT References: <33@christmas.UUCP> <14998@smoke.brl.mil> Sender: news@inmos.co.uk Reply-To: nathan@inmos.co.uk (Nathan Sidwell) Organization: INMOS Limited, Bristol, UK. Lines: 42 In article <14998@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >In article <33@christmas.UUCP> rtm@island.COM (Richard Minner) writes: >>Something I've been curious about, should the above be >>#define INT_MIN (-2147483648) > >Yes. > >>The precedence rules seem to imply that ()'s aren't needed >>with a negative integer constant. > >There are contexts that could cause trouble, e.g. "x-INT_MIN" >or "x=INT_MIN". While the C standard requires that these work >as expected, many older C implementations will misinterpret >these. Well gcc -ansi doesn't, source is #define NUM -10 main() { int x; x = x-NUM; x = 1/**/2; } preprocessor output is main() { int x; x = x--10; x = 1 2; } which fails, note that it is partly correct as the /**/ has been reduced to a space. This is gcc 1.36, has it been fixed in later versions? Nathan Sidwell, INMOS Ltd, UK JANET: nathan@uk.co.inmos Generic disclaimer applies UUCP: ukc!inmos!nathan This space unintentionally filled INTERNET: nathan@inmos.com