|
-
June 19th, 2001, 11:47 AM
#1
bitfield sizing
I wrote the code below to check the sizing of
bitfield structures. In Visual C++, I get a size
of 4 bytes no matter what I've tried. How do I
get this to map to 2 bytes?
Jim.
#include <stdio.h>
#include <windows.h>
#pragma pack(1)
// REGISTER WORD LAYOUTS
// Host To IF Register
typedef struct { // Mode
unsigned reset_if : 1; // All
unsigned service_request : 1; // RT
unsigned subsystem_flag : 1; // RT
unsigned host_to_micro_interrupt : 1; // BC
unsigned dbcacc : 1; // RT
unsigned start_minor_cycle : 1; // All
unsigned sa30_wraparound : 1; // RT
unsigned hbs_bor : 1; // All
unsigned rt_address : 5; // All
unsigned rt_parity : 1; // All
unsigned enable_tx_error : 1; // BC
unsigned interrupt_ctrl : 1; // All
} HOST_TO_IF_REG_FIELDS;
typedef union {
HOST_TO_IF_REG_FIELDS field;
USHORT value;
} HOST_TO_IF_REG_TYPE;
int main(int argc, char* argv[])
{
HOST_TO_IF_REG_TYPE content;
content.value = 0xAAAA;
printf("HOST to IF regtype size is %d\n", sizeof(content) );
printf("reset_if: %08X\n", content.field.rt_address);
return 0;
}
#pragma pack()
-
June 19th, 2001, 02:29 PM
#2
Re: bitfield sizing
Try:
// REGISTER WORD LAYOUTS
// Host To IF Register
typedef struct { // Mode
unsigned short reset_if : 1; // All
unsigned short service_request : 1; // RT
unsigned short subsystem_flag : 1; // RT
unsigned short host_to_micro_interrupt : 1; // BC
unsigned short dbcacc : 1; // RT
unsigned short start_minor_cycle : 1; // All
unsigned short sa30_wraparound : 1; // RT
unsigned short hbs_bor : 1; // All
unsigned short rt_address : 5; // All
unsigned short rt_parity : 1; // All
unsigned short enable_tx_error : 1; // BC
unsigned short interrupt_ctrl : 1; // All
} HOST_TO_IF_REG_FIELDS;
-
June 20th, 2001, 01:05 PM
#3
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|