Why does Eclipse CDT say: 'syntax error', but compilation no problem

前端 未结 10 1591
庸人自扰
庸人自扰 2021-02-04 08:04

I am working in existing C code which has a couple of lines with statements similar to this one:

struct collect_conn *tc = (struct collect_conn *) 
     ((char *         


        
10条回答
  •  自闭症患者
    2021-02-04 08:38

    It seems the CDT parser doesn't like the portion offsetof(struct ...). If you declare collect_conn using a typedef the error goes away. At least for me, the following code works:

    typedef struct  {
       struct runicast_conn runicast_conn;
       struct announcement announcement;
       const struct collect_callbacks *cb;
       struct ctimer t;
       uint16_t rtmetric;
       uint8_t forwarding;
       uint8_t seqno;
    } collect_conn;
    ...
    struct collect_conn *tc = (struct collect_conn *)
         ((char *)c - offsetof(collect_conn, runicast_conn));
    

    If you can't change the original declaration do something like this:

    typedef struct collect_conn collect_conn_t;
    

提交回复
热议问题