s - stands for "static"
g - is used for global constants and enums
gm - is used for global variables.
User is the one that provides the private-public categories, by following standard rules. For example, if you are writing code for a protocol stack. You definetely need to manage public vs private categories while encapsulating the layers of the stack. In a communication stack, the network layer must have functions and variables only accesible by itself, to prevent other processes to change those internal-private variables. This guarantees proper functionaility of the layer itself , as a black box. The public functions and variables are the ones available for the upper layer (e.g. application framework) to use and modify as pleased.
So basically it all depends on encapsultating services, or processes in the form of libraries or black boxes. You dont need to know whats happening inside, you just need to understand the inputs signals and the expected outputs. So this is not pertinent of the language itself, its more like a "doing readable code", "fancy code", "quality assurance code"...
_d - means a configuration definition that helps to solve pre-compilation configuration. For example:
PlatformToUse_d FRMD_K64F
Inside the code it is used:
#if FRMD_K64F == PlatformToUse_d
// configure GPIOs for FRDM board....
......
_c - means a constant value.
PlatformToUse_c (2000)
_t - means a type definition.
uint8_t means unisigned char.
Hope this helps.
Dear Alan
Thanks for good answer.
Could you explain about the prefix?
Here is example.
mNwkProtocolVersion_c
gAppStackProfile_c
if( gmUserInterfaceMode == gApplicationMode_c)
And any other prefix and/or suffix??
g is for Global variables.
m is for modular variables. Meaning the variable is defined inside a module / library, and only accesible by that specific .c file. Even that linker saves an specific memory location for it. This module variable works inside a black box. :smileyhappy:
gm is quite interesting. I dont remember seeing that in the code. Could you please share where you've seen this?
Update:
talking with a peer, looks like g is related to global constants and enums. while gm is more for variables. Please help me to review that while using our stack, and let me know anything that goes outside this statement. :smileyhappy:
Dear Alan
I found the prefix 'gm' on the ASL
And it looks like ... ( I am not quite understand 'gm' yet....)
prefix g : global (It make sense to me)
prefix m: moulder (local)
prefix s: looks like constant
prefix p: pointer
prefix z:
On the 'ASL_Userinterface.c'
/******************************************************************************
*******************************************************************************
* Private memory declarations
*******************************************************************************
******************************************************************************/
const uint8_t gsASL_LeaveNetwork[] = "Leave network";
#if (gCoordinatorCapability_d)
const uint8_t gsASL_StartingNwk[] = "Starting Network";
#else
const uint8_t gsASL_StartingNwk[] = "Joining Network";
#endif
.....
.....
uint8_t *gpszAslAppName;
const uint8_t gszAslCfgMode[] = "Cfg";
const uint8_t gszAslAppMode[] = "App";
const uint8_t gszAslNoNwkAddr[] = "----";
......
......
/******************************************************************************
*******************************************************************************
* Public memory declarations
*******************************************************************************
******************************************************************************/
/* Variables to keep track of the status of the Display on the AppMode or ConfigMode */
// ASL_DisplayStatus_t gAppModeDisplay;
// ASL_DisplayStatus_t gConfigModeDisplay;
// uint8_t gmUserInterfaceMode;
ASL_Data_t gAslData;
uint8_t gmUserInterfaceMode;
++++++++++++++++++
And additional question.
How It categorize Public and Private in C?
I don't think C can inheritance...
s - stands for "static"
g - is used for global constants and enums
gm - is used for global variables.
User is the one that provides the private-public categories, by following standard rules. For example, if you are writing code for a protocol stack. You definetely need to manage public vs private categories while encapsulating the layers of the stack. In a communication stack, the network layer must have functions and variables only accesible by itself, to prevent other processes to change those internal-private variables. This guarantees proper functionaility of the layer itself , as a black box. The public functions and variables are the ones available for the upper layer (e.g. application framework) to use and modify as pleased.
So basically it all depends on encapsultating services, or processes in the form of libraries or black boxes. You dont need to know whats happening inside, you just need to understand the inputs signals and the expected outputs. So this is not pertinent of the language itself, its more like a "doing readable code", "fancy code", "quality assurance code"...