Page 1 of 1

Struct and Enum Question

Posted: Wed Dec 19, 2007 7:38 am
by Kieran
Hi guys, I am creating structures to hold the Floppy Disk Controller information from the HW Ports.

I am wondering; s it possible to crete an enumeration of values (2Bits) within a structure.

Example:

Code: Select all

typedef struct {
        unsigned selected_unit:2;
        unsigned selected head:1;
        unsigned rw_not_ready:1;
        unsigned equipment_check:1;
        unsigned seek_complete:1;
        enum {
             command_successfull=0;
             terminated_abnormally=1;
             invalid_command=2;
             terminated_ready_change=3;
        } last_command_status:2;
} PACKED Command_Status_Register; // 0x3f5 (Read Only)

Posted: Wed Dec 19, 2007 8:53 am
by JamesM
Well if nothing else you could just do:

Code: Select all

enum __unnamed {
command_successful=0,
terminated_abnormally=1,
invalid_command=2,
terminated_ready_change=3
};
typedef struct { 
        unsigned selected_unit:2; 
        unsigned selected head:1; 
        unsigned rw_not_ready:1; 
        unsigned equipment_check:1; 
        unsigned seek_complete:1; 
        __unnamed last_command_status:2; 
} PACKED Command_Status_Register; // 0x3f5 (Read Only)
But, to be honest, with the exception of having semicolons where there should be commas in the enum definition I don't see why your code wouldn't compile.

Posted: Wed Dec 19, 2007 10:10 am
by os64dev

Code: Select all

typedef struct {
        unsigned selected_unit:2;
        unsigned selected_head:1;
        unsigned rw_not_ready:1;
        unsigned equipment_check:1;
        unsigned seek_complete:1;
        enum {
             command_successfull=0,
             terminated_abnormally=1,
             invalid_command=2,
             terminated_ready_change=3,
        } last_command_status:2;
} __attribute__((packed)) Command_Status_Register; // 0x3f5 (Read Only) 
compiled fine under gcc