Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: James Kuyper Newsgroups: comp.lang.c Subject: Re: I am learning C: a little problem with a simple source code Date: Fri, 04 Nov 2011 18:15:37 -0400 Organization: A noiseless patient Spider Lines: 38 Message-ID: <4EB46409.2090004@verizon.net> References: <27db9617-8ff5-455a-8a90-ed40c1e4b7c2@p20g2000prm.googlegroups.com> <3cd13578-0463-46aa-9dae-9a548afb5117@l19g2000yqc.googlegroups.com> <9hau9pFelvU2@mid.individual.net> <9bd83721-7b79-46ec-8a3e-9d967bb8000e@f11g2000vbm.googlegroups.com> <28ed3a50-7f6d-4f15-a12f-391935385e6e@a12g2000vbz.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="2P71cupDoazVVolqpw1jrw"; logging-data="4567"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IwIhhp1eBytDS6g4OpLG6KuYuTeW4rUg=" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110920 Thunderbird/3.1.15 In-Reply-To: <28ed3a50-7f6d-4f15-a12f-391935385e6e@a12g2000vbz.googlegroups.com> Cancel-Lock: sha1:DkbsDf0si655jGqXNIMkeLJB0yI= Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:12732 On 11/04/2011 05:21 PM, ImpalerCore wrote: ... > 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.