I have many different 3 axis sensors I am writing test code for. In the C files for each of them, I have the same char string defined:
char axis[3][8] = {\"X\",
If you must put it in a header file, use extern
or static
:
// option 1
// .h
extern char axis[3][8];
// .c
char axis[3][8] = { "X", "Y", "Z" };
// option 2
// .h
static char axis[3][8] = { "X", "Y", "Z" };
Extern tells the linker that there is a global variable named axis
defined in one of our implementation files (i.e. in one .c
file), and I need to reference that here.
static
, on the other hand, tells the compiler the opposite: I need to be able to see and use this variable, but don't export it to the linker, so it can't be referenced by extern or cause naming conflicts.