I’m a new C programmer, so this is a pretty basic question. What is the preferred approach to organizing ANSI C files in a project? I have about a dozen .c files each with their own .h file to hold local declarations, enums, etc. But I also have quite a few global parameters such as…
float LandingAltitudeList[2][17] = {
// P100
{12,-1000,0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000},
// P300
{16,-1000,0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,1000,12000,13000,14000} };
enum PType {P100,P300};
enum Boolean {No=0,Yes=1,Off=0,On=1};
In addition, I have a number of global variables such as…
float Alt_min = LandingAltitudeList[PhenomType][1];
int Max = LandingAltitudeList[PhenomType][0];
float Alt_max = LandingAltitudeList[PhenomType][Max];
which I calculate just once, but use throughout the project. These need to be in a function in order to work.
How should I organize my files to handle these global parameters? Many thanks.
One option is to declare these variables in a header file. It would be probably more appropriate to make the variables themselves invisible and to declare access functions to interface them. Consider the following example:
calculate_secretis called just once, when the module is initialized, andaccess_secret, when the variable value is needed. It is easy to enhance the system by adding array index parameter for arrays.