I have a C source code in which I declare:
Code:
main()
{
float variable=0;
float * tab;
tab=malloc(10000*sizeof(float));
/* Function where I pass variable & tab that contains a loop assigning values to tab[i] */
}
For now I put a malloc (10000) instead of [] because I intend to eventually make the size variable at runtime.
The problem I encounter is that "variable" is allocated to address 0X0013fe9C, while the address is pointing 0X0013fe0 tab. Result: the execution of my 4th loop (tab [3] points to 0X0013fe9C, because in my case sizeof (float) = 4) crushes "variable".
What I do not understand is that the memory location of "variable" is reserved for the compilation, while that by pointing tab via the malloc is reserved for the execution. I thought the two were separated. I'm using VS Express 2008.
Bookmarks