Today I started working on FUSE opensource code, there i found few lines like this:
struct fuse_session;
struct fuse_chan;
I don’t know how to interpret it , as far as i knew ‘struct‘ is followed by structure name and then the name of variable. Where as in this case there is only one named entity followed by struct ,so this fuse session is structure variable or structure name itself.It may be some really basic thing but i am not able to find it anywhere.
This is usually used for one of the following:
You want to let the user of some module to know that this struct exist, but don’t want to expose it’s content. For example:
in api.h:
in your internal file:
This way you encapsulate the implementation and may change the struct later if needed without any impact on the using module.
You want to use a structure (pointer) before declaring it. For example:
One important note:
If you only have the struct declaration, as in your question, you cannot refer to the struct directly, nor you may use the
sizeofoperator, only declare a pointer to the structure.