X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f Date: Thu, 27 Dec 2001 17:39:27 -0500 Message-Id: <200112272239.fBRMdR232033@envy.delorie.com> From: DJ Delorie To: djgpp AT delorie DOT com In-reply-to: (matt AT mattshouseofpain DOT com) Subject: Re: DJGPP: #define problems References: Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > #define BASEVAL1 233 > #define BASEVAL2 BASEVAL1 + 29 > #define BASEVAL3 233 > #define BASEVAL4 BASEVAL1 + 57 > > printf("baseval4 - baseval2 [28] = %d\n\n", BASEVAL4 - BASEVAL2); Use "gcc -E" and you'll see what's happening: BASEVAL4 - BASEVAL2 BASEVAL1 + 57 - BASEVAL1 + 29 233 + 57 - 233 + 29 Yup, 57 + 29 is 86, not 28. I suggest paranoid parens in your defines: #define BASEVAL1 233 #define BASEVAL2 (BASEVAL1 + 29) #define BASEVAL3 233 #define BASEVAL4 (BASEVAL1 + 57) You should always use parens (1) around use of arguments in a #define taking arguments, and (2) around the whole #define's value, when it's an expression. Example: #define TWICE(A) ((A)+2) The inner parens are in case you do TWICE(y^4), the outer parens are in case you do TWICE(j)*4