This code compiles, but no surprises, it fails while linking (no main found):
Listing 1:
void main();
Link error: \mingw\lib\libmingw32.a(main.o):main.c:(.text+0x106) undefined reference to _WinMain@16′
But, the code below compiles and links fine, with a warning:
Listing 2:
void (*main)();
warning: ‘main’ is usually a function
Questions:
-
In listing 1, linker should have
complained for missing “main”. Why
is it looking for _WinMain@16? -
The executable generated from
listing 2 simply crashes. What is
the reason?
Thanks for your time.
Case 1. is Windows-specific – the compiler probably generates
_WinMainsymbol whenmainis properly defined.Case 2. – you have a pointer, but as static variable it’s initialized to zero, thus the crash.