[courses] [c] lesson 11: enumerating boolean/hacking vim

Julie txjulie at austin.rr.com
Fri Nov 15 08:26:33 EST 2002


Morgon Kanter wrote:
> 
> > > enum boolean {false, true};
> > > #define boolean enum boolean
> >
> > You might want to reconsider this and use a typedef instead.
> >
> > typedef enum {false, true} boolean;
> 
> that would work better I guess. But when putting both through a sizeof, they
> are both needlessly 4 bytes. It seems the most economical way is
> #define boolean short
> #define false 0
> #define true 1

Size isn't everything.  No, really, it isn't ;-)  Perhaps
20 or 30 years ago when memory was entirely too scarce, sure.
Four bytes out of a 4KB memory might have been very meaningful,
but 4 bytes out of 1GB ... I think not.

There's more to economy than counting bytes.  For example,
if you pass a (char) parameter, you're still very likely
passing an (int) because the stack has to be word (32-bit
or 64-bit) aligned.  Except that now the compiler might be
emitting some weird instruction to sign-extend or clear
your (char) into an (int).  So now instead of a single
simple move-word instruction you're running a load, sign-extend,
move-word sequence.  Amusing, no?

ANYWAY, simple is good.  I'm working on a design at work
to fix some 15 year old crud.  One of the guys who worked
on it decided to typedef his own types (!) and now I have
to go make sense of it.  Moral of the story -- stick with
the basics.  It'll keep your programs simpler and prevent
you from being an object lesson ;-)
-- 
Julianne Frances Haugh             Life is either a daring adventure
txjulie at austin.rr.com                  or nothing at all.
					    -- Helen Keller



More information about the Courses mailing list