Accessing bit fields using a union problem.
Hello - I changed my code from my last post:
http://cboard.cprogramming.com/showthread.php?t=109945
so that the struct of bit fields is unionized with a UINT32 word:
Code:
#include <stdio.h>
typedef union
{
struct {
/// Reserved - read as 0
unsigned reserved : 30;
/** This bit contains the interrupt status. Reading this register
* clears this bit.
*/
unsigned stats : 1;
/** This field masks the interrupt.
* 0 - Masked
* 1 - Enabled
*/
unsigned maskn : 1;
} bits;
unsigned long word;
} volatile RegStruct;
RegStruct *hwReg
When I print out hwReg.word I get the entire correct 32 bits - BUT when I print out one of the bits hwReg.bits.maskn, I get 0x00000000 - I think it still may be accessing the bits as bytes even though the struct is unionized with UINT32. what is going on?