4 ms·
The function called at program startup is named main, which this translation unit defines. No other may therefore define it. Binaries that don't run main are ou
by to3m 9y ago
The function called at program startup is named main, which this translation unit defines. No other may therefore define it. Binaries that don't run main are out of the scope of the standard, and so irrelevant to the discussion.
Anyway, as a more general point: your argument is, basically, "the customer is wrong". But the customer is never wrong! Therefore your argument is invalid.
- belovedeagle 9y ago> The function called at program startup is named main, Incorrect. On Linux usually _start is called first and this can be freely changed at link time. LPT: Knowing a bit of JavaScript or whatever doesn't make you a systems engineer; don't act like it.
- to3m 9y agoRight, yes, sure, whatever. Since you've evidently got the experience that I apparently lack, you'll know that this point is irrelevant, since the topic at hand is Standard C, and not whatever some random implementation happens to do... so I'm not sure what your point is. But of course perhaps it would be obvious to a more experienced practitioner. C standard reference: https://port70.net/~nsz/c/c11/n1570.html#5.1.2.2.1 https://port70.net/~nsz/c/c11/n1570.html#5.1.2.2.1 (A freestanding environment may start anywhere - but such environments are unusual.)
- belovedeagle 9y agoNothing in the C standard prohibits parts of the executable from (a) being outside the "program" and thus many of the limitations of the standard, and (b) running before main. Therefore on Linux and Windows and almost certainly OS X too, main is not called first. Anyone who knows anything about systems programming knows this or should. (See also: the 90 million My First Disassembly blog posts out there.) But you know what else the c standard says? UB is UB. People in here complaining that UB is really unfair because it forces them to write correct programs are the ones bringing the real world into scope in this discussion. If you want to insist that we limit the discussion to the standard then you're just objectively wrong by definition, end of discussion. I was trying to be more productive than that.