I have global pointer to the array, lets say that it has declaration like shown below.
uint8_t * g_ptr;
I have some function
void foo(uint8_t no_devices);
which will be used to allocate arrays of desired size.
Pointer returned by function malloc() will be stored in g_ptr. This will work like champ if dynamic allocation is successful, but what if malloc() return NULL value.
I have an idea how to handle this kind of error and just want to get your opinion.
do
{
g_ptr = (uint8_t *) malloc(no_devices * 8);
}
while(g_ptr == NULL)
Is this good idea, or is there another way to handle this kind of errors?
I am using avr-gcc compiler.