I am reading a book and it states the following principle for what to put in the header file:
"What you can put into header files? The basic rule is “only declarations,” that is, only information to the compiler but nothing that allocates storage by generating code or creating variables. This is because the header file will typically be included in several translation units in a project, and if storage for one identifier is allocated in more than one place, the linker will come up with a multiple definition error ..."
However, it then gives an example of such header file:
#ifndef STACK_H
#define STACK_H
struct Stack
{
struct Link
{
void* data;
Link* next;
void initialize(void* dat, Link* nxt);
} *head;
...
};
#endif
Isn't the variable "head" an object and violating this rule? Even it is a pointer, it will take storage and cause issues if multiple compilation units include this header file leading to "multiple definition"?