I'm coding on MPLAB, using the XC32 compiler, and trying to get the hang of using dynamic memory, so I created a basic example program:
#include <stdlib.h>
#include <plib.h>
char x;
char y;
char main(void)
{
Nop();
char *pLocation = (char *)malloc(16);
if(pLocation == 0x00)
{
return 0;
}
for(x = 0;x<=7;x++)
{
*pLocation = x;
pLocation++;
}
while(1)
{
Nop();
}
}
Problems:
- When the pointer gets to the
malloc
call line, the value ofpLocation
is forced to 0x00 meaning that it somehow managed to fail to pass me pointer information from the heap. - When the pointer gets to assigning the value of
x
to the location of the pointerpLocation
I get a Bus Exception saying Unimplemented RAM memory access. I suspect this is because I tried to write to 0x00.
Am I doing something wrong in the code?
Additional Information:
- I have already assigned a heap of 16 bytes.
- I get the same error for memory requests of even size 2.
- I am using the MPLAB SIM debugger.
- MPLAB Version 8.87.00.00.
- Building with the XC32 compiler.