Including C header file with lots of global variables
Posted
by Costi
on Stack Overflow
See other posts from Stack Overflow
or by Costi
Published on 2010-05-19T19:18:19Z
Indexed on
2010/05/19
19:20 UTC
Read the original article
Hit count: 256
I have an include file with 100+ global variables. It's being used in a library, but some programs that I'm linking the lib to also need to access the globals.
The way it was built:
// In one library .c file
#define Extern
// In the programs that use the globals
#define Extern extern
// In the .h file
Extern int a,b,c;
I had a hard time understanding why the original programmer did that so I removed that define Extern stuff. Now I think I understand the thing about TU with the help of stackoverflow: 1, 2, 3.
Now I understand that I should define the global variables in one .c file in the library and use extern in the .h file. The problem is that I don't want to duplicate code.
Should I go back to that #define Extern voodoo?
© Stack Overflow or respective owner