For a moment I was very proud of myself to have written my probably first C bug-free program. Here is the entire source code:

int main;

It compiles perfectly even without the int, but a warning is issued (even without -Wall) and, as a programmer who is aiming at a bug-free program, I treat them as errors.

Having happily compiled this application, I immediately rushed to launch it. To my surprise, a segmentation fault error appeared...


Now seriously. What is exactly happening?

My guess is as follows: it's the lack of main's definition. This is so obvious and yet the compiler permits it. OK, main may be defined in a different unit. But even the linker doesn't do anything about it. Any particular reason why?

Edit
Report