简体   繁体   English

C中“ *”令牌错误之前的预期“)”

[英]expected ')' before '*' token error in c

The following is my .h file 以下是我的.h文件

  1 typedef int32_t status_t;
  2 typedef u_int16_t pic_id_t;
  3 typedef const char* (*pic_flavor_t) (pic_t *);
  4 typedef status_t (*pic_periodic_t) (pic_t *);
  5 typedef status_t (*pic_get_port_info_t) (pic_t *pic, u_int16_t link,void  *info,boolean *need_update);
  6 
  7 struct pic_
  8 {
  9     u_int16_t   nic_slot;
  10     u_int16_t   pic_slot;
  11     u_int32_t   pic_flags;
  12     pic_id_t    pic_id;
  13     u_int16_t   pic_asic_type;
  14     u_int16_t   pic_firstport;
  15     pic_periodic_t  pic_periodic;
  16     pic_flavor_t    pic_flavor;
  17     pic_get_port_info_t pic_get_port_info;
  18     void *pic_context;
  19 }pic_t;
  20 

and these are the errors i have got. 这些是我遇到的错误。

../../../../../src/pfe/common/drivers/rpio/rpio_tunnel_pvt1.h:3: error: expected ')'   before '*' token
../../../../../src/pfe/common/drivers/rpio/rpio_tunnel_pvt1.h:4: error: expected ')' before '*' token
../../../../../src/pfe/common/drivers/rpio/rpio_tunnel_pvt1.h:5: error: expected ')' before '*' token
../../../../../src/pfe/common/drivers/rpio/rpio_tunnel_pvt1.h:15: error: expected specifier-qualifier-list before 'pic_periodic_t'

I am trying to create a new .h file for my .c file. 我正在尝试为我的.c文件创建一个新的.h文件。 Here I am including definitions of a few structures required in my .c file I'm unable to tackle these errors. 在这里,我在.c文件中包括了一些所需结构的定义,但我无法解决这些错误。

The following seems to work 以下似乎有效

typedef struct pic_ pic_t;
typedef int32_t status_t;
typedef u_int16_t pic_id_t;
typedef const char* (*pic_flavor_t) (pic_t *);
typedef status_t (*pic_periodic_t) (pic_t *);
typedef status_t (*pic_get_port_info_t) (pic_t *pic, u_int16_t link,void  *info, boolean *need_update);

struct pic_
{
    u_int16_t   nic_slot;
    u_int16_t   pic_slot;
    u_int32_t   pic_flags;
    pic_id_t    pic_id;
    u_int16_t   pic_asic_type;
    u_int16_t   pic_firstport;
    pic_periodic_t  pic_periodic;
    pic_flavor_t    pic_flavor;
    pic_get_port_info_t pic_get_port_info;
    void *pic_context;
};

You are using pic_t in: 您在以下位置使用pic_t

typedef const char* (*pic_flavor_t) (pic_t *);

but you ahave defined pic_t type after this. 但是您已经在此之后定义了pic_t类型。

struct pic_
{
    ...
}pic_t;

So pic_t is not available/not known to compiler at this instant (at line #3). 因此, pic_t (第3行)不可用/对于编译器未知。

To remove the error, declare this structure before using pic_t type. 要消除该错误,请在使用pic_t类型之前声明此结构。

Ah! 啊! You also need to typedef the struct to pic_t not make it as an structure object. 您还需要将struct typedef设置为pic_t而不使其成为结构对象。

Well it is better explained with code in user3386109 's answer. 好吧,最好在user3386109的答案中用代码解释。

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

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