I am supposed to make a program based on a header file and some further description. The problem working with opaque type is needed. Opaque struct is declared in header file with some other functions. But each function is supposed to have its own .c file and here comes the question. What should I do or where should I define the opaque struct so my functions can work with that?
I have files like:
header.h source.c(main) function1.c fuction2.c etc.
And in this situation I have no idea what to do.
Your global header file should define a type name without its implementation, along with prototypes of functions to create, destroy and handle data of that type.
header.h
Then you need an internal header, which provides an implementation for the structure.
xyzintheader.h
Then files with implementations for specific routines will use the internal header, because they need to know the structure details to access them.
xyzcreate.c
xyzcreatf.c
xyzdestr.c
xyzmodif.c
And external modules will use the public header, because they only need to know the structure exists and what tools to use to handle it.
source.c