boolean

cepek at spanky.mgi.com cepek at spanky.mgi.com
Wed Jun 6 07:25:04 AEST 1990


In article <16784 at haddock.ima.isc.com>, karl at haddock.ima.isc.com
(Karl Heuer) writes:
> In article <20.266429f6 at spanky.mgi.com> Cepek at MGI.COM writes:
>> Among our "company-common" .H files, the compiler/target-machine dependent
>> one includes the following pseudo-types:
>> #define bool    int8	/* smallest entity for TRUE or FALSE	*/
>> #define boolean int	/* fast/simple entity for TRUE or FALSE	*/
>>
>> This allows the programmer to choose between space and speed.
> 
> Defining both `bool' and `boolean', with different meanings, is probably a
> mistake.  The very existence of a typedef named `int8' is questionable.  (Yes,
> I know the reason.)

I will (have) start(ed) a separate thread for this topic.

>                      And it's probably not worthwhile to have the `small'
> type, since if you have enough of them that the factor of (probably) 4 is
> significant, you might as well also go for the factor of (probably) 8 that you
> get by using packed bit vectors.  (The time cost isn't as bad as one often
> hears, since you don't normally have to go around packing and unpacking the
> things--the common operations on booleans are test, set, and clear, none of
> which is hard.  The only real pain is that you can't use normal C syntax; you
> have to go through macros.)

OK, so to summarize the ups and downs of both ways of implementing "bool":
           _int_8_bool_                     _bitfield_bool_
	normal C syntax      versus     using "painful" macros
        quicker              versus     "not too bad" time cost
        less dense           versus     more dense (twice)

The most significant item for me, a programmer using this, is item #1.
The last thing I want to have to cope with is an awkward syntax for doing
something simple.  Also, switching from using a "bool" to using a "boolean"
(or vice versa), is very easy (if rare).  Item 2 is nice, but not significant
(for us).  Item 3 is also not very important in our situation; we appreciate
the extra density beyond "boolean", but maximal density isn't important.

                  - - - - - - - - - - - - - - - - - - - - 

I'm not trying to start a war here.  I've only been using C for 4 years
(programming for 12).  I'm all for learning new methods and discussing
alternative approaches; in fact I enjoy it.

+------------------------------------------------------------------------+
|  Michael Cepek                               "Engage."                 |
|  Programmer/Analyst                                                    |
|                                       Internet:  Cepek at MGI.COM         |
|  Management Graphics, Inc.               Voice:  +1 612/851-6112       |
|  1401 East 79th Street                Operator:  +1 612/854-1220       |
|  Minneapolis, MN  55425  USA               Fax:  +1 612/854-6913       |
+------------------------------------------------------------------------+



More information about the Comp.lang.c mailing list