Reputation: 8230
I am currently writing my own programming language, mainly for educational purposes.
When writing a simple hello world example, I realised that many programming languages take the following form:
write "hello world" to the console
return 0
I am unsure what to tag this question as, any help is appreciated of course.
Upvotes: 3
Views: 235
Reputation: 14550
It's a OS specific question, so no-one can answer if it's true for all OS. That said, I believe that, in any reasonable OS, yes - a program has to have a return value.
Why? To chain the programs execution and therefore to report problems, relaunch and so on. There aren't programs that don't return a value, it's just a compiler that hides it from a programmer.
Is this the case on all major operating systems? Probably. 0 usually means means success but you shouldn't make such assumptions when writing your programs; use language constants.
If you write your own language you may map your error codes (exceptions, termination reasons) to the host language's error codes.
Upvotes: 1