xishiquanqiu
xishiquanqiu
采纳率0%
2019-07-20 15:30 阅读 498

使用结构体名->定义的新的变量编译出错,贴详细代码,请解释疑问


//IDE环境:keil5  以下代码编译后没有错误
typedef struct Lednum
{
    unsigned char bit0 : 1;   //结构体成员表列
    unsigned char bit1 : 1;
    unsigned char bit2 : 1;
    unsigned char bit3 : 1;
    unsigned char bit4 : 1;
    unsigned char bit5 : 1;
    unsigned char bit6 : 1;
    unsigned char bit7 : 1;
}BitLedNum_Typedef;          //结构体变量名

typedef union             //定义一个共用体
{
    BitLedNum_Typedef bits; //结构体变量名定义的 bits(结构体变量名可以用来定义??不是应该用结构体名Lednum来定义吗)
    BYTE Flag;
}BitNum;

 volatile  BitNum BitLed8Num; //用共用体变量名 定义新的共用体(同理,不是用该用共用体名定义吗)
 volatile  BitNum BitLed4Num;

#define Led8Num0 (BitLed8Num.bits.bit0) 
#define Led8Num1 (BitLed8Num.bits.bit1)
#define Led8Num2 (BitLed8Num.bits.bit2)
#define Led8Num3 (BitLed8Num.bits.bit3)
#define Led8Num4 (BitLed8Num.bits.bit4)
#define Led8Num5 (BitLed8Num.bits.bit5)
#define Led8Num6 (BitLed8Num.bits.bit6)
#define Led8Num7 (BitLed8Num.bits.bit7)




//添加结构体,共用体名,定义新的结构体共用体,IDE编译出错
typedef struct LedNum
{
    unsigned char bit0 : 1;
    unsigned char bit1 : 1;
    unsigned char bit2 : 1;
    unsigned char bit3 : 1;
    unsigned char bit4 : 1;
    unsigned char bit5 : 1;
    unsigned char bit6 : 1;
    unsigned char bit7 : 1;
}BitLedNum_Typedef;

typedef union Bitnum
{
    LedNum bits;     //unknown type name 'LedNum' 
    BYTE Flag;
}BitNum;

 volatile  Bitnum BitLed8Num;   //unknown type name 'Bitnum'
 volatile  Bitnum BitLed4Num;

#define Led8Num0 (BitLed8Num.bits.bit0)  //request for member 'bits' in something not a structure or union
#define Led8Num1 (BitLed8Num.bits.bit1)
#define Led8Num2 (BitLed8Num.bits.bit2)
#define Led8Num3 (BitLed8Num.bits.bit3)
#define Led8Num4 (BitLed8Num.bits.bit4)
#define Led8Num5 (BitLed8Num.bits.bit5)
#define Led8Num6 (BitLed8Num.bits.bit6)
#define Led8Num7 (BitLed8Num.bits.bit7)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • weixin_45363440 weixin_45363440 2019-07-20 15:37

    LedNum bits; //unknown type name 'LedNum'
    正确定义struct LedNum bits;
    类型名是struct LedNum;

    点赞 1 评论 复制链接分享

相关推荐