I have a coding style/code optimisation related question. I need to declare an array which will contain some sensor data. This array needs to be available in two scopes measurement.c and communication.c.
Can you tell me what option in your opinion is better: 1. When an array is declared globally within measurement.c and then I will use fcn to get a pointer to this array in different scope.
uint8_t* gPtr = (NULL); // initialising as a null pointer
void sensorDriver(void)
{
static uint8_t arr[10]; // local array
gPtr = arr; // assigning local address to global pointer
// some other code which getting and processing data
}
const uint8_t* getArrPtr(void)
{
return gPtr;
}
- When an array is declared locally and I will have a global pointer which will have assigned local array address.
uint8_t arr[10]; // global array
void sensorDriver(void)
{
// some other code which getting and processing data
}
const uint8_t* getArrPtr(void)
{
return arr;
}
Data can be received in the same way for two methods: communication.c
void sendData(void)
{
const uint8_t* arrPtr = getArrPtr();
{