[comp.unix.questions] Atomic #defines

dg@lakart.UUCP (David Goodenough) (08/11/89)

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 <stdio.h>, 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		  	  +---+