4 ms·
UB comes with high-level languages. "main" is not specified in the high-level language, but by the OS. You write some machine code, give it the name "main" and
by delinka 9y ago
UB comes with high-level languages. "main" is not specified in the high-level language, but by the OS. You write some machine code, give it the name "main" and the OS jumps to that location and starts executing. One should adhere to the "C calling convention" (managing the stack correctly) if that code is expected to behave within the system.
But "main is not a function" does not produce undefined behavior.
- clarry 9y ago> "main" is not specified in the high-level language, but by the OS. You write some machine code, give it the name "main" and the OS jumps to that location main() is specified by C. The OS as such doesn't know or care about main. Headers in the binary executable specify where the OS should begin execution, and this is rarely in main.
- monochromatic 9y agoIf you're feeding source code to a C compiler, it makes sense to ask whether or not it contains UB.