BellyTelly
Programmer
Hi folks,
following issue concerns C only:
due to the fact that many global variables in our project leads to many problems (unpredictable side-effects) I want to isolate them. That is, I want to create an extra file where I group some global variables decorating them with static attribute. Besides, I create some functions which have the unique right to alter the global variables.
At a thight view it looks like OOP, as I give the files names like I would give them classes. By this way I can separate concerns and assure that no dumb function can directly alter the state of global variables.
In order to have a more precise idea what I mean here is an example:
file status.c:
#define UP_LIMIT 25
#define LO_LIMIT 3
#define SET_ERROR -100
static int vi_status;
int getVi_Status()
{
return (vi_status);
}
int setVi_Status(int new_status)
{
if (new_status > LO_LIMIT && new_status < UP_LIMIT)
{
vi_status = new_status;
}
else
return (SET_ERROR);
}
-----------
file myproject.c:
//Here I can alter the state of vi_status by get-/setVi_Status only. In addtion, the use of these functions apparently shows a modification of global vi_status.
Does anybody agree with me or has got another approach hiding his/her global variables?
Any hint is highly appreciated.
Yours BellyTelly
following issue concerns C only:
due to the fact that many global variables in our project leads to many problems (unpredictable side-effects) I want to isolate them. That is, I want to create an extra file where I group some global variables decorating them with static attribute. Besides, I create some functions which have the unique right to alter the global variables.
At a thight view it looks like OOP, as I give the files names like I would give them classes. By this way I can separate concerns and assure that no dumb function can directly alter the state of global variables.
In order to have a more precise idea what I mean here is an example:
file status.c:
#define UP_LIMIT 25
#define LO_LIMIT 3
#define SET_ERROR -100
static int vi_status;
int getVi_Status()
{
return (vi_status);
}
int setVi_Status(int new_status)
{
if (new_status > LO_LIMIT && new_status < UP_LIMIT)
{
vi_status = new_status;
}
else
return (SET_ERROR);
}
-----------
file myproject.c:
//Here I can alter the state of vi_status by get-/setVi_Status only. In addtion, the use of these functions apparently shows a modification of global vi_status.
Does anybody agree with me or has got another approach hiding his/her global variables?
Any hint is highly appreciated.
Yours BellyTelly