简体   繁体   English

使用交叉编译器(arm-none-eabi-gcc)Typedef文件中的外部结构

[英]Typedef an externel structure in file using cross-compiler (arm-none-eabi-gcc)

I'm trying to compile a project which consist of severel source fies & header files & includes some structure definiton. 我正在尝试编译一个包含严重源文件和头文件并包含一些结构定义的项目。 But when I compile an error comes 但是当我编译错误时

"error: expected specifier-qualifier-list before 'typedef'" in file "uip.h" 文件“ uip.h”中的“错误:'typedef'之前的预期specifier-qualifier-list”

I have a structure in file named as "httpd.h" 我在名为“ httpd.h”的文件中有一个结构

    struct httpd_state {
    unsigned char timer;
    struct psock sin, sout;
    struct pt outputpt, scriptpt;
    char inputbuf[50];
    char filename[20];
    char state;
    struct httpd_fsdata_file_noconst *file;
    int len;
    char *scriptptr;
    int scriptlen;
    unsigned short count;
    };

I want to typedef this structure in another file named as "uip.h" 我想在另一个名为“ uip.h”的文件中对该结构进行typedef

    struct uip_conn {
    uip_ipaddr_t ripaddr;   /**< The IP address of the remote host. */
    u16_t lport;        /**< The local TCP port, in network byte order. */
    u16_t rport;        /**< The local remote TCP port, in network order. */
    u8_t rcv_nxt[4];    /**< The sequence number that we expect toreceive next. */
    u8_t snd_nxt[4];    /**< The sequence number that was last sent by us. */
    u16_t len;          /**< Length of the data that was previously sent. */
    u16_t mss;          /**< Current maximum segment size for the connection. */
    u16_t initialmss;   /**< Initial maximum segment size for the connection. */
    u8_t sa;            /**< Retransmission time-out calculation state variable. */
    u8_t sv;            /**< Retransmission time-out calculation state variable. */
    u8_t rto;           /**< Retransmission time-out. */
    u8_t tcpstateflags; /**< TCP state and flags. */
    u8_t timer;         /**< The retransmission timer. */
    u8_t nrtx;          /**< The number of retransmissions for the last segment sent*/
  /** The application state. */
   **typedef struct httpd_state uip_tcp_appstate_t;
   uip_tcp_appstate_t appstate;**
   } __attribute__((packed));

Can anyone please help?? 谁能帮忙吗?

You can't have a typedef statement inside a struct definition. 您不能在struct定义中包含typedef语句。 Either hoist it outside of the struct , or don't use the typedef at all: 将其提升到struct之外,或者根本不使用typedef

// Option #1: Hoisting
typedef struct httpd_state uip_tcp_appstate_t;
struct uip_conn {
    ...
    uip_tcp_appstate_t appstate;
};

// Option #2: No typedef
struct uip_conn {
    ...
    struct httpd_state appstate;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM