X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f Message-ID: <3C2BA7B8.FBFA1D33@worldnet.att.net> From: Les Cargill X-Mailer: Mozilla 4.72 [en] (Win98; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: DJGPP: #define problems References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 69 Date: Thu, 27 Dec 2001 22:54:09 GMT NNTP-Posting-Host: 12.86.209.132 X-Complaints-To: abuse AT worldnet DOT att DOT net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1009493649 12.86.209.132 (Thu, 27 Dec 2001 22:54:09 GMT) NNTP-Posting-Date: Thu, 27 Dec 2001 22:54:09 GMT Organization: AT&T Worldnet To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Matt wrote: > > Hi All, > > I have am having a problem with the way #define's are being handled. I > have some sample code to demonstrate the problem. > > I have commented the source to explain the problem. > > Basically when i do some math with the #define's the compiler looks > like it is selecting the wrong data type. > > I have upgraded from 2.954 binaries to v3.03 binaries but this didn't > fix the problem. > > If anyone has a suggestion i would appreciate it. > > Regards, > Matt > (matt AT mattshouseofpain DOT com) > > /**START**/ > #include > #define BASEVAL1 233 > #define BASEVAL2 BASEVAL1 + 29 > #define BASEVAL3 233 > #define BASEVAL4 BASEVAL1 + 57 > > int main(void) > { > printf("baseval1 [233] = %d\n", BASEVAL1); > printf("baseval2 [262] = %d\n\n", BASEVAL2); > printf("baseval3 [233] = %d\n", BASEVAL3); > printf("baseval4 [290] = %d\n\n", BASEVAL4); > > /* up to this point the define's are ok but when the math is done > on > the next line it seems to be treating the result as an unsigned > char > data type. */ > printf("baseval4 - baseval2 [28] = %d\n\n", BASEVAL4 - BASEVAL2); > > /* here is a sanity check */ > printf("290 - 262 [28] = %d\n", 290 - 262); > > return(0); > } > /**END**/ If you'll parenthesize the right-hand side of the #defines for BASEVAL2 and BASEVAL4, you'll get the expected results: #define BASEVAL2 (BASEVAL1 + 29) ... #define BASEVAL4 (BASEVAL1 + 57) The macro preprocessor simply substitutes the text "33 + 29" when it sees BASEVAL2. It doesn't group them together into a single quantity. So "printf("baseval4 - baseval2 [28] = %d\n\n", BASEVAL4 - BASEVAL2);" becomes "printf("baseval4 - baseval2 [28] = %d\n\n", 33 + 57 - 233 + 29); -- http://home.att.net/~lcargill