码迷,mamicode.com
首页 > 其他好文 > 详细

error: expected declaration specifiers or '...' before xxx(xxx是函数形参)

时间:2018-10-24 16:47:37      阅读:560      评论:0      收藏:0      [点我收藏+]

标签:解决   ted   type   ati   情况   指针变量   描述   cal   before   

在使用带参有返回值的函数指针做参数时,编译出现下面情况

……………………

error: expected declaration specifiers or ‘...‘ before ‘FunType‘

 

情形描述:

a.h:

typedef void (*FunType)();

void callFun(FunType p);

 

a.c :

#include "a.h"

FunType myfuntype=NULL;

void callFun(FunType p)

{

  myfuntype=p;

}

b.c

#include "a.h"

MyFun()

{

  .....;

}

callFun(MyFun);

函数指针变量FunTypevar  定义在 a.c 中,a.h声明 了 相应的typedef 和函数 .在b.c 想使用a.c中函数指针,于是在b.h中#include"a.h",最后出现了上面的编译错误。

 

原因分析:

网上搜索,讨论的不少,越看越茫然。

可能原因是

b.h中#include "a.h" 而a.h中的函数声明中用到了b.h中的结构体或者typedef,那么就会出现在包含a.h的时候b.h中的结构体或者typedef还没有声明,从而陷入错误.

解决办法:

将a.h 删除

a.c:

typedef void (*FunType)();

FunType myfuntype=NULL;

void callFun(FunType p)

{

  myfuntype=p;

}

b.c

typedef void (*FunType)();

extern void callFun(FunType p);

MyFun()

{

  .....;

}

callFun(MyFun);

 

当再次make 的时候,pass了

error: expected declaration specifiers or '...' before xxx(xxx是函数形参)

标签:解决   ted   type   ati   情况   指针变量   描述   cal   before   

原文地址:https://www.cnblogs.com/cyyljw/p/9844240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!