Atomic #defines (was Re: Password checking program)

Steve Summit scs at adam.pika.mit.edu
Thu Aug 17 14:22:22 AEST 1989


In article <652 at lakart.UUCP> dg at lakart.UUCP (David Goodenough) writes:
>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.

Is this true?  Harbison and Steele (not necessarily a definitive
pANS reference, I know) imply that it is always -1; at least,
their discussion (p. 311 in the second edition) includes the
example line

	#define EOF (-1)

I agree that depending on the value is a bad idea, but it can be
easy to write code which does so.  One way is to start defining
your own error codes which might be returned, along with EOF,
from some intermediate-level input routines:

	#define ERROR (-2)

A better way (which is portable as long as you know that all
successful returns are positive) is

	#define ERROR (EOF-1)

The only trouble here is that the header file in which you
#define ERROR then ought to #include <stdio.h>, but that isn't
necessarily a good idea under old implementations...


                                            Steve Summit
                                            scs at adam.pika.mit.edu



More information about the Comp.lang.c mailing list