3 ms·
Not just in Visual Studio. main is usually (always?) not the entry point on unixoid systems either, that's much more likely to be _start, which calls main() dow
by anyfoo 5y ago
Not just in Visual Studio. main is usually (always?) not the entry point on unixoid systems either, that's much more likely to be _start, which calls main() down the line.
Nevertheless, main is treated specially by the compiler for the aforementioned historical reasons, for example to not warn/error out if it does not return a value despite the type clearly telling so.
Observe:
% echo 'int main(void) { }' > foo.c; clang -c foo.c
<no output>
% echo 'int foo(void) { }' > foo.c; clang -c foo.c
foo.c:1:17: warning: non-void function does not return a value [-Wreturn-type]
int foo(void) { }
^
1 warning generated.
As you can see, clang is happy to ignore the missing return value for main(), but not for foo().
- hermitdev 5y agoAlso, just as execution doesn't start in main, it also doesn't end with main, either. In C, you can register `atexit` handlers. You can do that in C++, too. In C++, you can also have "user" code executed before & after main by virtue of static initialization & destruction.