Xref: utzoo comp.unix.questions:15647 comp.lang.c:20676 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!network!ucsd!ames!xanth!mcnc!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.unix.questions,comp.lang.c Subject: Atomic #defines (was Re: Password checking program) Message-ID: <652@lakart.UUCP> Date: 11 Aug 89 13:14:49 GMT References: <15257@duke.cs.duke.edu> Followup-To: comp.lang.c Organization: Lakart Corporation, Newton, MA Lines: 33 From article <15257@duke.cs.duke.edu>, by ndd@macbeth.cs.duke.edu (Ned D. Danieley): > Another problem is: > ... >>? #define ENDOFFILE -1 > ... >>? done=ENDOFFILE; > > some compilers will interpret this as the old =- assignment > operator. this is one place where style can really make a difference: > > done = ENDOFFILE; > > is easier to read and doesn't piss off cc. The correct solution is 1. Use, and EOF, because there are no guarantees that EOF has to be -1: I could use -42 if the spirit so moved me. 2. #define ENDOFFILE (-1) with the original, it is left as an excercise to see why some compilers will barf on: a = x-ENDOFFILE; With parentheses, the problem is avoided completely, so style doesn't come into it. -- dg@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+