Quote:
Originally Posted by JetLinus
Hm, don't really understand that (yet).
|
Say you have compiler-error.c:
Code:
#include "useful.h"
#include "useful.h"
(In reality you'd include the same thing twice indirectly rather than directly like this but the result is the same.)
And useful.h:
Code:
typedef struct { } useful_type;
Then my compiler errors, with the slightly unhelpful message "conflicting types for `useful_type'". This can be solved using #define's as you suggest. It's a compilation issue, it's solved with a compilation tool, the preprocessor.
Now say you have c1.c and c2.c, each identical:
Code:
typedef struct { } useful_type;
void useful_function() { }
Each will compile fine. It doesn't matter that you define the same type twice if it's in different files. In fact, you generally have to do so. Types are instructions for the compiler, so you need them included in each source file you use them in.
But when you try to link c1.o and c2.o the linker will error "multiple definition of `useful_function'". This is a linking issue, so isn't something solved using #define's in the manner you describe.
This is all second nature if you use the convention pab describes: useful.c for definitions, useful.h for declarations. I just wanted to point out that inline functions do indeed go in headers.