Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!shelby!agate!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Is #define THING -10 completely safe? Message-ID: <9884@dog.ee.lbl.gov> Date: 14 Feb 91 07:43:04 GMT References: <33@christmas.UUCP> <1702@svin02.info.win.tue.nl> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 45 X-Local-Date: Wed, 13 Feb 91 23:43:04 PST In article <1702@svin02.info.win.tue.nl> debra@svin02.info.win.tue.nl (Paul de Bra) writes: > if INT_MAX is 2147483647 then INT_MIN should not be written as > -2147483648 but as (-2147483647-1) Paul is correct here. The type and value of -2147483648 are unsigned long and 2147483648 respectively (on a typical two's complement 32-bit machine). The constant is made up of two subexpressions, namely unary minus and the integral constant `2147483648', and the latter is an unsigned long. Negation does not alter the type, and in this particular case it leaves the value unchanged as well. >-2147483648 is a (constant) expression, not evaluated by the preprocessor >but by the compiler. Actually, it is at times evaulated by both. The preprocessor has arithmetic that is similar to, but not the same as, that in the compiler. When I discovered this I raised a very minor fuss (a fusslet? fusslette? :-) ) since it complicates the preprocessor, which must understand unsigned values (including U-suffixed constants): #include void a() { #if -1 > 1 printf("bad\n"); #else printf("good\n"); #endif } void b() { #if -1U > 1 printf("good\n"); #else printf("bad\n"); #endif } int main() { a(); b(); return 0; } must print `good' twice. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab EE div (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov