[Courses] [C] boolean and other common names (was lesson 7)

Akkana akkana at shallowsky.com
Sat Nov 9 20:47:31 EST 2002


> OK! Is true, in C there is no boolean data, but (there is but :-)
> you can simulate the boolean data. The boolean data is practically an
[ ... ]
> u> #define boolean int
> u> #define false 0
> u> #define true 0

One caution: I would strongly recommend against setting up #defines or
enums for common terms such as "true" or "false".  The problem is that
you may set up defines for this, and then two or three of the packages
you use may also think it's a good idea, and suddenly you have all these
conflicting definitions, which you have to reconcile somehow, for
instance with #undef true and #undef false between including one header
file and the next.  Ugh.  The same goes for defining a type called
"String": Don't do it!  (I once worked on a project where we included
header files from three separate packages which each defined mutually
incompatible String types.  Ours would have been the fourth.

The best solution to this is to have your own namespace prefix.
For instance, in mozilla there's a class called nsString, and a
type called PRBool (ns stands for netscape, where the class originated,
and PR is for the nspr library).  GTK code tends to have names that
start ith g_ or gtk_.  Doesn't matter what you pick; just pick a short
prefix -- could be your initials, or your domain name, or the first
few letters of the program or project you're working on, anything that
makes it less likely that your names will collide with common names in
include files.

	...Akkana



More information about the Courses mailing list