Re: [cc65] enum size

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2009-10-19 11:20:08
On Mon, Oct 19, 2009 at 02:04:23AM +0200, Johan Kotlinski wrote:
> Just a thing I came to think of, when I was messing around with bit
> fields. Wouldn't it be possible to reduce the size of enums?

Not easily. Other things have to be changed to do this, and these things have
a negative impact on code size and speed.

> typedef struct {
>     enum { Foo, Bar } my_enum;
>     int bit : 1;
> } MyStruct;
>
> ...sizeof(MyStruct) is now 3. Shouldn't it be possible to reduce this
> to 2 or even 1?

sizeof(MyStruct) should be 4, not 3.

You can use

    enum { Foo, Bar };
    typedef struct {
        unsigned char my_enum;
        int           bit : 1;
    } MyStruct;

to reduce the size to 3.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Oct 19 11:21:18 2009

This archive was generated by hypermail 2.1.8 : 2009-10-19 11:21:21 CEST