M
Mark
Hello
#include <stdlib.h>
int main(void)
{
int *i;
i = malloc(sizeof *i);
*i = 1;
free(i);
*i = 2;
return 0;
}
Compiling this with 'gcc' with just about every flags reasonably
possible, I don't get any warnings from compiler.
This code runs and doesn't crash, that surprises me. I expected that
referring to a pointer's contents after the pointer's memort was freed
would cause some 'special effects' on my system. Isn't this code
supposed to cause undefined behavior ?
Could you please explain why is it so? Thanks!
PS. Moreover even lint stays silent.
#include <stdlib.h>
int main(void)
{
int *i;
i = malloc(sizeof *i);
*i = 1;
free(i);
*i = 2;
return 0;
}
Compiling this with 'gcc' with just about every flags reasonably
possible, I don't get any warnings from compiler.
This code runs and doesn't crash, that surprises me. I expected that
referring to a pointer's contents after the pointer's memort was freed
would cause some 'special effects' on my system. Isn't this code
supposed to cause undefined behavior ?
Could you please explain why is it so? Thanks!
PS. Moreover even lint stays silent.