How can i check whether malloc() was fail in Keil C?
unsigned char xdata malloc_mempool [0x100];
void display()
{
unsigned char xdata *ptr;
int a;
init_mempool (&malloc_mempool, sizeof(malloc_mempool));
ptr = malloc(9000000);
if(ptr != 0)
{
a = 7;
free(ptr);
} else {
a = 9;
}
}
As stated in http://www.keil.com/support/man/docs/c51/c51_malloc.htm malloc will return null pointer if there is not enough memory to satisfy the allocation request. It is obviously not so mush memory in 8051. But the result of a is always 7.