Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!uunet!mcsun!hp4nl!svin02!debra From: debra@svin02.info.win.tue.nl (Paul de Bra) Newsgroups: comp.lang.c Subject: Re: Is #define THING -10 completely safe? Message-ID: <1702@svin02.info.win.tue.nl> Date: 29 Jan 91 11:15:44 GMT References: <33@christmas.UUCP> Organization: Eindhoven University of Technology, The Netherlands Lines: 21 In article <33@christmas.UUCP> rtm@island.COM (Richard Minner) writes: >In article <1991Jan23.015757.22220@portia.Stanford.EDU> fangchin@portia.Stanford.EDU (Chin Fang) writes: >>... from my /usr/include/limits.h >>#define INT_MIN -2147483648 /* min decimal value of an "int" */ As James Clark reminded me a long time ago, -2147483648 is a (constant) expression, not evaluated by the preprocessor but by the compiler. This has 2 implications: 1) as people have said before, the replacement is purely textual, so the unary minus can be misused as a binary minus when writing something like 5 INT_MIN 2) this define is not supposed to work at all if 2147483648 is not a legal positive integer. (on most machines it isn't) if INT_MAX is 2147483647 then INT_MIN should not be written as -2147483648 but as (-2147483647-1) so your limits.h is at fault, and some compilers (including gcc) will not treat your INT_MIN as a large negative number, because of integral promotion. (2147483648 is promoted to unsigned because it is too large for a signed int) Paul. (debra@win.tue.nl, debra@research.att.com)