You can be tricky like this:
- int countVal = 100;
-
static int * const prwGlobalCountVal = &countVal;
-
static const int * const proGlobalCountVal = &countVal;
-
...
-
void myFunction()
-
{
-
int countVal;
-
// for read/write access to global variable
-
... *prwGlobalCountVal ...
-
// for read-only access to global variable
-
... *proGlobalCountVal ...
-
// to use local variable
-
... countVal ...
-
}
But this is a good way to outsmart yourself. Much better to change the name of the local variable so there is no collision.
Notice that this trick creates one or two aliases of the global variable. Therefore, you must make a point of
not associating the
restrict type qualifier with the global variable.
A good lint will warn you if a local name overrides a wider-scope name.