Claudiu Claudiu - 1 year ago 121
C Question

shared global variables in C

How can I create global variables that are shared in C? If I put it in a header file, then the linker complains that the variables are already defined. Is the only way to declare the variable in one of my C files and to manually put in

s at the top of all the other C files that want to use it? That sounds not ideal.

Answer Source

In the header file write it with extern. And at the global scope of one of the c files declare it without extern.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download