Sunday, July 12, 2009

Sharing a variable between source files in C?

I'm aware of using the extern keyword to provide one source file access to a global variable in another file...but it seems a little messy. Is there a more correct way (or another way) of sharing variables between source files (without using system calls for shared memory, pipes, etc.) In C++ you can create a class with a static member, but in C you cannot have static members in structures. Any ideas?


Thanks

Sharing a variable between source files in C?
Nothing wrong with globals when that is really what it takes. Most modern C compilers support namespaces now, and that can be a way of encapsulating the data.





BTW, a static class is still a global underneath.


No comments:

Post a Comment