I started learning openGL and also started splitting my project in multiple source files for the first time too. As such I'm still a bit confused and sometimes I feel my variables are scattered around especially since openGL requires extensive use of global variables. At the moment I got about 15 files.
My major problem is that some variables are for example shared by some modules and some other variables are shared only by a few of those and some other modules. If I put all these variables in a common.h file will there be any problems (performance-wise) since not all variables will be used by all modules?
Using the above method I also have the problem that if I use types defined in other header files I have to include those too. I could also use '#if (defined' macros, but that doesn't seem the most appropriate method.
Including extern
declarations for unused variables shouldn't cause performance problems (definitely not at run-time, but it will introduce an imperceptibly small overhead at compile-time).
It will, however, result in your code being less maintainable. Best practice is to organize your globally-scoped variables and functions into headers based on use or purpose. Things that are conceptually related go in the same header, and things that are unrelated go in different headers. That makes it easier to include the functionality that you need without pulling in massive amounts of junk that you don't.
I wouldn't consider it a problem that you need to include headers in order to pull in datatype definitions. That's just part of how the C language works. You can make it easier for yourself by ensuring that all of your headers are self-sufficient. That is, if a header uses a particular datatype, that header should include the header where that type is defined. That way, your .c files don't have to worry about analyzing the header and figuring out what other headers need to be included. Headers that aren't self-sufficient can also lead to problems where code builds differently (or not at all) depending on the order in which the headers were included.