1

我正在尝试编译一个项目,该项目由严重的源文件和头文件组成,并包含一些结构定义。但是当我编译一个错误来了

文件“uip.h”中的“错误:‘typedef’之前的预期说明符限定符列表”

我在名为“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;
    };

我想在另一个名为“uip.h”的文件中键入这个结构

    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));

有人可以帮忙吗??

4

1 回答 1

3

定义中不能有typedef语句struct。要么将其提升到 之外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;
};
于 2013-09-16T19:19:36.613 回答