Boolean Operators Slighted in C

Ray Butterworth rbutterworth at watmath.UUCP
Fri May 9 23:16:30 AEST 1986


> > lots of us say "typedef short bool" in our .h files.
> typedef char bool;	uses less space on some machines.

And on some machines it uses more space.  Some machines can
reference an int with a single instruction, but checking the
value of a byte might take several.  The one I am using now
does the "if(integer)" test in 4 bytes of machine instructions,
but "if(character)" takes 12 bytes.

So defining it as short or char instead of int might save you
1 or 3 bytes of storage, but it also might cost you several
times this amount EVERY time you reference the variable.
In general you should always use int (or long).  short (or char)
should only be used for structures read in from an external
source or for large arrays where the saving in space for the
data is significantly large.

Of course if you aren't worried about portable efficiencies
do whatever is best for your machine.  On the other hand, I'd
like to think that at least some of the software I write now
will still be running in 10 years, but I have my doubts about
whether or not some of the machines I am using now will still
be here then.  (I can think of some wonderful code I wrote for
an IBM1620 not much more than 10 years ago.)



More information about the Comp.lang.c mailing list