Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!brutus.cs.uiuc.edu!ux1.cso.uiuc.edu!iuvax!copper!bomgard From: bomgard@copper.ucs.indiana.edu (Tim Bomgardner) Newsgroups: comp.lang.c Subject: Re: TRUE and FALSE Message-ID: <55856@iuvax.cs.indiana.edu> Date: 30 Aug 90 17:16:53 GMT References: <1990Aug29.153917.28110@warwick.ac.uk> Sender: news@iuvax.cs.indiana.edu Organization: Indiana University, Bloomington IN. Lines: 65 In article <1990Aug29.153917.28110@warwick.ac.uk> asrap@warwick.ac.uk (Sean Legassick) writes: >[...] > And how about some more: > > #define EQUALS == > #define LESSTHAN < ...... ad infinitum You're gonna laugh, but I never got Fortran out of my system (so to speak). After a couple coding errors early in my C career of the form if (x = y) ... and if (x << y) ... I put the following defines in a .h file: #define EQ == #define NE != #define LT < #define NOT ! #define AND && #define OR || etc. Another guy I know went even further, with defines such as #define THEN { #define ELSE } else { #define ENDIF } etc. It actually made converting a lot of old fortran programs to C go pretty quickly. > Okay, so maybe I'm going over the top a little - but you get my point. >Personally I go further than simply using TRUE and FALSE (which by the way >I always define as (1==1) and (1==0), not for portability but for a little >extra clarity and any compiler worth its salt will optimise them down anyway). > I have in a standard header file a typedef for bool (which I typedef >to an int, although if I used ANSI extensions I could add even more clarity >and typedef to an enum { false, true }. This I find is invaluable for >clarities sake. An int declaration says to me this variable is going to hold >a scalar value - which is very different from a boolean one. > I would be interested in anyone who thinks an int declaration of >a boolean variable is clearer. The only argument against my method I can think >of is that of standardisation - bool isn't a standard C type and shouldn't >be as it is still basically an int. However of all the additional types >I have seen in people's source, bool is the one I've seen most often. Well, depending on how you look at it, *everything* is an int (of one length or another). That's no reason to eliminate a data type. Data abstraction is one of the reasons we use high level languages in the first place. typedef bool makes perfect sense and is in keeping with the C tradition of never spelling any word out if it can be avoided (if u cn rd ths, u cn wrt pgms n C). And for all you fortran fans out there, how bout #define LOGICAL int (yes, that's there in my friend's .h file, as well as INTEGER, REAL, etc.). I DEFINE all my case labels, magic numbers, etc., and more often than not my variable names have more than 12 characters instead of less. At least I can look at code I wrote a couple years ago with a good chance that I'll have some clue as to what it was I thought I was doing.