I have exported the __heap_base label from the startup file of keil (__heap_base is a label pointing to the starting of heap). In a c file declared the __heap_base as extern and assigned the address of __heap_base to a void pointer.But this void pointer always has the value 0x00000000 and thus cannot be used to point to the base of heap. So my indirect question is how to store the base address of heap in a pointer and use it as arguments for memory management functions that i may declare and definie
#include <stdint.h>
extern uint32_t __heap_base;
void* original_heap_base=&__heap_base;
/*void get_heap_base()
{
original_heap_base=&__heap_base;
}*/
void* mem_init()
{
void *temp=original_heap_base;
original_heap_base+=4;
return temp;
}
int main()
{
int *p=(int*)mem_init();
*p=5;
return 0;
}
User contributions licensed under CC BY-SA 3.0