Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!esosun!cogen!alen From: alen@cogen.UUCP (Alen Shapiro) Newsgroups: comp.unix.questions Subject: Summary Re: Brain-dead Unix tutor needs quick help (-1) Message-ID: <391@cogen.UUCP> Date: Fri, 20-Nov-87 15:40:40 EST Article-I.D.: cogen.391 Posted: Fri Nov 20 15:40:40 1987 Date-Received: Mon, 23-Nov-87 04:14:45 EST References: <387@cogen.UUCP> <6700@brl-smoke.ARPA> Reply-To: alen@cogen.UUCP (Alen Shapiro) Organization: Cogensys, LaJolla, Calf. Lines: 38 Firstly, thanks to ALL who replied by mail and net. It seems that there is no "knock-em-dead" reason for the statement #define XXX (-1) to have ()s round the "-1". i.e. On an ANSI standard C compiler (when one is finally decided on :-)) there are NO situations where LEGAL use of XXX results in a LEGAL program that differs in function with or without ()s surrounding the "-1". Certainly antequated C compilers will probably screw-up and make statements like a = XXX into a =- 1 (which (strictly speaking) is no longer legal C). There IS a reason for fully bracketing expressions within #define since #define XXX a+b followed by y * XXX is probably not what is meant There is also a reason for fully bracketing ALL pseudo variables within preprocessor functions like #define XXX(a,b) ((a)+(b)) in case 'a' or 'b' are expressions themselves when used in the code. The closest to a REAL reason for not using #define XXX -1 came from Steve Schlaifer who suggested that x= -XXX becomes x= --1 which unfortunately is not legal C or it would have been a superb counter. There IS the case where #define XXX -i (note the "i" not "1" here) which results in legal C but does not answer the original question exactly. In this case there is also an issue of good coding (what was the person doing with a global variable manipulated from a #define - can you say "side-effect"). The answer I will use in this case will be one of style. It is good practise to ALWAYS bracket expressions in case they come back to bite you or you happen to port through an old compiler. Always bracketing expressions (it should become a habit) will save debugging time and the programmer should not be concerned with special cases that are immune to the specific effect (in case, being human, (s)he misses an important counter). So, thanks again, I don't feel quite as much of an idiot now (all I have to work on is being an a** hole :-)) --alen the Lisa slayer (it's a long story)