打印
[ARM入门]

KEIL中结构体和共用体的定义使用问题

[复制链接]
9832|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hyelectron|  楼主 | 2014-4-23 13:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 hyelectron 于 2014-4-23 13:57 编辑

问题:如下,为何LPC17XX.h中的定义没问题,而自己照着定义确要添加名字才可以编译通过,请问是什么问题?

1. LPC17XX.h中如下定义
typedef struct
{
  union {
    __IO uint32_t FIODIR;
    struct {
      __IO uint16_t FIODIRL;
      __IO uint16_t FIODIRH;
    };
    struct {
      __IO uint8_t  FIODIR0;
      __IO uint8_t  FIODIR1;
      __IO uint8_t  FIODIR2;
      __IO uint8_t  FIODIR3;
    };
  };
//。。。。。。。
}LPC_GPIO_TypeDef;

2.个人的定义 ----编译有问题
typedef struct
{
    union
    {
        int u_wnk;
        struct {
        short int m_cos;
        short int m_sin;
        };
    };
}FFTWNK_TypeDef;

编译出现的问题:
warning:  #40-D: expected an identifier
warning:  #40-D: expected an identifier
  error:#618: struct or union declares no named members

3.如下改正编译才通过
typedef struct
{
    union
    {
        int u_wnk;
        struct {
        short int m_cos;
        short int m_sin;
        }meb; //添加结构体名
    }uni; //添加共用体名
}FFTWNK_TypeDef;

相关帖子

沙发
ayb_ice| | 2014-4-24 10:02 | 只看该作者
本帖最后由 ayb_ice 于 2014-4-24 10:04 编辑

main.c(41): error:  #3093: anonymous structs are only supported in --gnu mode, or when enabled with #pragma anon_unions

使用特权

评论回复
板凳
ayb_ice| | 2014-4-24 10:12 | 只看该作者
#pragma anon_unions
struct A
{
    struct
    {
        int i, j;
    };               // Okay -- references to i and j
};                   // through class A are allowed.

int foo(int m)
{
    A a;
     a.i = m;
     return a.i;
}

使用特权

评论回复
地板
hyelectron|  楼主 | 2014-4-25 15:12 | 只看该作者
ayb_ice 发表于 2014-4-24 10:12
#pragma anon_unions
struct A
{

拜谢! 看来还是要好好研究下KEIL的编译参考指南啊。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

10

帖子

0

粉丝