J
James Kuyper
On 11/04/2011 05:21 PM, ImpalerCore wrote:
....
AFAIK, the exit status from a program is used in Unix-like systems only
for communication between child processes and their parents, pipes need
not be involved, and usually aren't. In my personal experience, a shell
(sh, csh, tcsh, bsh, etc.) and make are the most common parent
processes. I'm not aware of any special connection between the exit
status and the use of pipes. Therefore, I find it odd that you might
consider pipes to have been the prime motivation for exit statuses.
Could you explain that idea in a little more detail?
Keep in mind that in C as it was originally designed, there was no
'void'. Functions declared with no return type were implicitly treated
as if they had a return type of 'int'. There were functions which didn't
bother setting the return value, and function calls which didn't bother
checking the return value, but there was no such thing as functions that
were declared as not returning a value. In such an environment, it would
be natural for main() to return an int, even if there was no particular
need to; and there was certainly a need for some mechanism whereby a
child process could report simple status information to its parent.
I wouldn't ridicule void main(); the only thing I've ever done is point
out that it's not supported by the standard. If it were added to the
list of permitted signatures for main(), I'd have no objection.
....
I'm curious about the whole 'int' return type placed on 'main' as
well. The only idea that I can come up with is that since Ritchie
designed C to support the Unix operating system, and the Unix
operating system wanted to implement pipes for inter-program
communication, 'int main(...)' became the de-facto standard to use the
return value in that sense.
AFAIK, the exit status from a program is used in Unix-like systems only
for communication between child processes and their parents, pipes need
not be involved, and usually aren't. In my personal experience, a shell
(sh, csh, tcsh, bsh, etc.) and make are the most common parent
processes. I'm not aware of any special connection between the exit
status and the use of pipes. Therefore, I find it odd that you might
consider pipes to have been the prime motivation for exit statuses.
Could you explain that idea in a little more detail?
Keep in mind that in C as it was originally designed, there was no
'void'. Functions declared with no return type were implicitly treated
as if they had a return type of 'int'. There were functions which didn't
bother setting the return value, and function calls which didn't bother
checking the return value, but there was no such thing as functions that
were declared as not returning a value. In such an environment, it would
be natural for main() to return an int, even if there was no particular
need to; and there was certainly a need for some mechanism whereby a
child process could report simple status information to its parent.
... What's interesting is that there are
other scenarios where returning a value from 'main' makes little to no
sense, like in embedded systems designed to run a single stand-alone
application "forever", with no opportunity for inter-process
communication, and yet 'void main(...)' is ridiculed even though it
seems to have a logical place in some application design domains.
I wouldn't ridicule void main(); the only thing I've ever done is point
out that it's not supported by the standard. If it were added to the
list of permitted signatures for main(), I'd have no objection.