Hacker News new | ask | show | jobs
by sdkmvx 4454 days ago
Show me where in the ANSI standard it says this is illegal. Implementation details do not matter. The Microsoft C compiler will compile a ANSI C89-conforming program into a runnable executable on Windows. The rest is undefined.

And while we're on implementation details, please note that most UNIX platforms do not start at main either. Most platforms include some soft of crt0 that must be linked which contains the real entry point. The dynamic linker will also run code prior to main.

But the C standard only defines what the environment looks like when execution begins and makes no statement on what might run before or how the program got into memory in the first place.

1 comments

Come to think of it, I don't think I've used any platform where main() is the real entry point to the executable. On Linux the real entry point is _start, all of the bare-metal embedded stuff I've touched does a whole bunch of hardware setup in crt0 before it calls main(), etc...
main() is the entry point function in newer OS X versions. Why ship crt0 in everything when you can put it in dyld?
crt0 would still get linked into static binaries in OSX, I presume.