一个简单的C程序问题,在IAR Embedded Workbench 编译器中出错的问题
#defineUcharunsignedchartypedefstruct{Ucharyear_k;Ucharyear;Ucharmonth;Uchardaytime;U...
#define Uchar unsigned char
typedef struct
{
Uchar year_k;
Uchar year;
Uchar month;
Uchar daytime;
Uchar hour;
Uchar minute;
}_boot_time;
Uchar a=1;
_boot_time boot_time={a,2,3,4,5,6};
void main()
{
Uchar *p_time_=(Uchar*)&boot_time;
}
这样编译会出错,说是结构体中必须是常量;但是 如果改为下面
#define Uchar unsigned char
typedef struct
{
Uchar year_k;
Uchar year;
Uchar month;
Uchar daytime;
Uchar hour;
Uchar minute;
}_boot_time;
Uchar a=1;
void main()
{
_boot_time boot_time={a,2,3,4,5,6};
Uchar *p_time_=(Uchar*)&boot_time;
}
这样又对 ,是为什么啊?为什么放在main函数里面又对了 求解!!!! 展开
typedef struct
{
Uchar year_k;
Uchar year;
Uchar month;
Uchar daytime;
Uchar hour;
Uchar minute;
}_boot_time;
Uchar a=1;
_boot_time boot_time={a,2,3,4,5,6};
void main()
{
Uchar *p_time_=(Uchar*)&boot_time;
}
这样编译会出错,说是结构体中必须是常量;但是 如果改为下面
#define Uchar unsigned char
typedef struct
{
Uchar year_k;
Uchar year;
Uchar month;
Uchar daytime;
Uchar hour;
Uchar minute;
}_boot_time;
Uchar a=1;
void main()
{
_boot_time boot_time={a,2,3,4,5,6};
Uchar *p_time_=(Uchar*)&boot_time;
}
这样又对 ,是为什么啊?为什么放在main函数里面又对了 求解!!!! 展开
2个回答
展开全部
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询