Recently i wrote the following program ...
#include <stdio.h>
int main(int argc,char** argv) {
int i;
i = 10;
printf("%d",i);
free(&i);
return 0;
}
The above program is compiled using GCC without errors. When you execute the output program the result in cygwin is:
10 36 [sig] a 1008 open_stackdumpfile: Dumping stack trace to a.exe.stackdump
and in FreeBSD
a.out in free(): warning: junk pointer, too high to make sense
The problem is that
free is trying to deallocate a variable that is supposed to be handled by the compiler's generated code. The question is ... should the compiler caught the error? I think after the compilation the error is likely untraceable.