例子:
#include "io430.h"
union iForm
{
unsigned int i;
unsigned char c[2];
};//占用空间 = 最大的变量占用的空间
struct iForm1
{
unsigned int i;
unsigned char c[2];
};//占用空间 = 依次占用空间之和
__no_init union iForm DetFlag @0x0200; //测试union 占用的内存空间
__no_init struct iForm1 DetFlag_1 @0x0202; //测试struct 占用的内存空间
/*******************************************************************************
* Function: main()
*
* Description: 采用硬件仿真的方式区分union和struct
*
* Calls: --
* Called by: --
* Globals: DetFlag DetFlag_1
* Input: void
* Output: Null
* Return: void
* Others: Null
*******************************************************************************/
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
DetFlag.i = 0x55aa;
DetFlag.c[0] = 0x11;
DetFlag.c[1] = 0x22;
DetFlag_1.i = 0x55aa;
DetFlag_1.c[0] = 0x11;
DetFlag_1.c[1] = 0x22;
for(;;)
{
// DetFlag.i = 0x01;
}
}
运行结果: