I tried the following code on both codepad.org and ideone.com:
char* ptr = new char;
free( ptr );
Yes, I know it’s undefined behavior, but I want to compile it and run it to see what happens.
Visual C++ 10 compiles it, but gcc which is used on the abovementioned sites says
error: expected constructor, destructor, or type conversion before ‘(’ token
Why wouldn’t this code compile with gcc and how could I make it compile?
This code indeed will not compile. You have to add
main()call also.