开发者

Having trouble using .h files to export functions

开发者 https://www.devze.com 2023-03-06 13:37 出处:网络
I have a .c file which has code for functions, and a .h file that sets up the function prototypes so they can be accessed from other files, but they are in conflict.

I have a .c file which has code for functions, and a .h file that sets up the function prototypes so they can be accessed from other files, but they are in conflict.

Here is the error I get:

file.c:111: error: ‘Function’ redeclared as different kind of symbol
file.h:16: error: previous declaration of ‘Function’ was here

In file.c:

#include "file.h"
...

void开发者_如何学Go *Function(const char *filename) {
    ...
}

In file.h:

typedef void (*Function)(const char *filename);

Thanks in advance!


You're creating typedef of a function pointer instead of a prototype. Your declaration says that variable of type Function is a pointer to a function returning nothing and accepting a const char*.

I think what you really want in the .h file is this:

void *Function(const char *filename);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号