typedefs, etc.
    Alan S. Driscoll 
    alan at allegra.UUCP
       
    Sat Jan 14 14:59:29 AEST 1984
    
    
  
	From: chris at umcp-cs.UUCP
	Newsgroups: net.unix
	Subject: Re: typedefs, etc. - (nf)
	Re:
		From: keesan at bbncca.UUCP
		[ Re: ...  typedef enum { FALSE, TRUE } bool; ... ]
		I question the utility of a 'bool' type which generates
		type-clashes with boolean expressions.  However, if you
		insist on using it, do you object to 
			return( (bool)(getchar() == 'y') );
		?  This avoids the type-clash warning, and is guaranteed
		to work.
	Unfortunately it's not *guaranteed* to work, unless you use
		typedef enum { FALSE = 0, TRUE = 1 } bool;
	to ensure that (bool) 0 == FALSE and (bool) 1 == TRUE.  Otherwise
	the result of a boolean expression may be neither FALSE nor TRUE!
You're wrong.  In fact,
	typedef enum { FALSE, TRUE } bool;
is guaranteed to do the right thing.  The C Reference Manual (September,
1980) states
	The identifiers in an enum-list are declared as constants, and
	may appear wherever constants are required.  If no enumerators
	with = appear, then the values of the corresponding constants
	begin at 0 and increase by 1 as the declaration is read from left
	to right.  An enumerator with = gives the associated indentifier
	the value indicated; subsequent identifiers continue the progression
	from the assigned value.
So, FALSE will be given the value 0 and TRUE the value 1 because of their
*positions* in the declaration.
It amazes me how much misinformation appears on the net.
	Alan S. Driscoll
	AT&T Bell Laboratories
    
    
More information about the Comp.unix
mailing list