Of course the code compiled and worked, it just did not define a type flags, it defined a variable called flags.
How to split up an application into mutiple modules is explained in every good C book.
Basically define the types in the header, declare the variables in the header and define every object
in one C file. But in order to know what is a type, a declaration or a definition, you still need to read a good C book first
.
In the end, it should look somehow like this:
Code:
/* file: header.h */
#ifndef _HEADER_H_
#define _HEADER_H_
#ifndef __cplusplus
extern "C" {
#endif
typedef struct {
unsigned char flag1 : 1;
unsigned char flag2 : 1;
unsigned char flag3 : 1;
} flags_type;
extern flags_type flags_var;
extern void fun(flags_type* ptr);
#ifndef __cplusplus
}
#endif
#endif /*_HEADER_H_ */
Code:
/* file: header.c */#include "header.h" flags_type flags_var;void fun(flags_type* ptr){ /* .. code .. */}