Cryptic C (YES/NO vs. TRUE/FALSE + other thoughts)

Wayne Throop throopw at rtp47.UUCP
Tue Aug 27 05:26:23 AEST 1985


In message 989 at gatech, Arnold Robbins gives an interesting example:

> #define FORCEWRITE	1
> #define NOFORCE		0
>
> #define APPEND		1
> #define NOAPPEND	0
>
> 	dowrite (file, FORCEWRITE, APPEND, ....);	/* call */
>
> int dowrite (file, force, append,...)	/* actual procedure */

I like this notion in general, but I point out a problem with it that a
(currently nonexistant) lint-like tool could help with.  What if the
call was done like so:

    dowrite( file, NOAPPEND, FORCEWRITE, ... );

This doesn't do remotely what you intend, and it very hard to detect.
What you "really want" is to be able to declare two enumerations, and
make lint check that you don't pass members of one enumeration to a
formal of another type.

Also, the "extra checking" that K&R says that lint-like tools are free
to do with typedefs would be welcome.  No current link (that I am aware
of) will allow using typedef as a type abstraction device.
-- 
Wayne Throop at Data General, RTP, NC
<the-known-world>!mcnc!rti-sel!rtp47!throopw



More information about the Comp.lang.c mailing list