Atomic #defines (was Re: Password checking program)

David Goodenough dg at lakart.UUCP
Fri Aug 11 23:14:49 AEST 1989


>From article <15257 at duke.cs.duke.edu>, by ndd at 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 at lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp at xait.xerox.com		  	  +---+



More information about the Comp.unix.questions mailing list