Programming, for all ages and all languages.
Kieran
Member
Posts: 54 Joined: Mon Apr 11, 2005 11:00 pm
Post
by Kieran » Wed Dec 19, 2007 7:38 am
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)
JamesM
Member
Posts: 2935 Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:
Post
by JamesM » Wed Dec 19, 2007 8:53 am
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.
os64dev
Member
Posts: 553 Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands
Post
by os64dev » Wed Dec 19, 2007 10:10 am
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