Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!hscfvax!mohamed From: mohamed@hscfvax.UUCP (750025@Mohamed_el_Lozy) Newsgroups: comp.unix.questions Subject: Re: Brain-dead Unix tutor needs quick help (-1) Message-ID: <473@hscfvax.UUCP> Date: Wed, 18-Nov-87 12:27:31 EST Article-I.D.: hscfvax.473 Posted: Wed Nov 18 12:27:31 1987 Date-Received: Sat, 21-Nov-87 04:56:12 EST References: <387@cogen.UUCP> Reply-To: mohamed@hscfvax.UUCP (750025@Mohamed_el_Lozy) Organization: Health Sciences Computing Facility, Harvard University Lines: 37 In article <387@cogen.UUCP> alen@cogen.UUCP (Alen Shapiro) writes: >One of the topics touches on good C coding practices. I've hit a mental >block about the reason ()s are used in preprocessor expressions like >#define XXX (-1). > >--alen the Lisa slayer (it's a long story) Here is a good general example of what can go wrong: % cat example.c #define RIGHT (4 + 4) /* RIGHT must be 8 under any circumstances */ #define WRONG 4 + 4 /* Will WRONG always equal 8? */ main() { printf("%d\n", 3*RIGHT); /* 3*8 = 24 */ printf("%d\n", 3*WRONG); /* Does it?? */ } % cc -o example example.c % example 24 16 To understand what happenned, use the c preprocessor: % /lib/cpp example.c # 1 "example.c" main() { printf("%d\n", 3*(4 + 4)); printf("%d\n", 3*4 + 4); <- ahaaa!! }