hut123
hut123

Reputation: 455

Having trouble using .h files to export functions

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 *Function(const char *filename) {
    ...
}

In file.h:

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

Thanks in advance!

Upvotes: 1

Views: 266

Answers (1)

Fred Larson
Fred Larson

Reputation: 62053

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

Upvotes: 4

Related Questions