I am trying to pass struct
pointer in function. I have a typedef
in file1.h, and want to only include that header to file2.c, because file2.h only need pointer. In C++ I would just write like I did here, but using C99 it doesn't work. If someone has any suggestions how to pass struct
pointer without full definition it would be very appreciated. Compiler - gcc.
file1.h
typedef struct
{
...
} NEW_STRUCT;
file2.h
struct NEW_STRUCT;
void foo(NEW_STRUCT *new_struct); //error: unknown type name 'NEW_STRUCT'
file2.c
#include "file2.h"
#include "file1.h"
void foo(NEW_STRUCT *new_struct)
{
...
}
I think you just have to name your structure, and do a forward declaration of it and after re typedef it.
First file:
typedef struct structName {} t_structName;
Second file:
struct stuctName;
typedef struct structName t_structName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With