Deutsch English Français Italiano |
<v4onrg$hmc2$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c Subject: Re: Whaddaya think? Date: Mon, 17 Jun 2024 09:16:00 +0200 Organization: A noiseless patient Spider Lines: 95 Message-ID: <v4onrg$hmc2$1@dont-email.me> References: <666ded36$0$958$882e4bbb@reader.netnews.com> <20240616015649.000051a0@yahoo.com> <v4lm16$3s87h$4@dont-email.me> <v4lmso$3sl7n$1@dont-email.me> <v4lr0m$3tbpj$1@dont-email.me> <8734pd4g3s.fsf@nosuchdomain.example.com> <v4ltuj$3trj2$1@dont-email.me> <87y17530a0.fsf@nosuchdomain.example.com> <v4mb92$3ak$1@dont-email.me> <87tths39yy.fsf@nosuchdomain.example.com> <v4oi9f$gnf3$1@dont-email.me> <877ceo2iqq.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 17 Jun 2024 09:16:01 +0200 (CEST) Injection-Info: dont-email.me; posting-host="d070642afdec4e1c027704024e3cba98"; logging-data="579970"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bWBm7kUV2nUzCClfTnHHv" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cancel-Lock: sha1:A1vUdGV13imGfU+AOLBTAKML/6A= X-Enigmail-Draft-Status: N1110 In-Reply-To: <877ceo2iqq.fsf@nosuchdomain.example.com> Bytes: 5369 On 17.06.2024 08:20, Keith Thompson wrote: > Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes: >> On 16.06.2024 22:32, Keith Thompson wrote: >>> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes: >>>> [...] K&R at >>>> least seems to say that 'void' can only be declared for the >>>> return type of functions that do not return anything. >>>> [...] >>> >>> No version of C has ever permitted "void main" except when an >>> implementation documents and permits it. [...] >> >> I cannot comment on main() being handled differently than >> other C functions. I was just quoting my old copy of K&R. > > First or second edition? It's a translation of a "(c) 1977 Prentice Hall" original, with no further edition mentioned, so it's probably the 1st edition? > > But main() *is* handled differently than other functions, Be assured, I don't object! It was just not mentioned that it's a special case. > and > that's important to understand. It's effectively called by the > environment, which means that your definition has to cooperate > with what the environment expects. I'm not sure whether my K&R copy addresses that at all. A quick view and I see only one instance where "main()" is mentioned at the beginning: main() { printf("hello, world\n"); } No types here, and no environment aspects mentioned. Also mind that (other) languages don't need to interact with the environment. Just recently I noticed that the Algol 68 Genie does not pass the value of the outmost block to the environment. Environment questions, interaction with the OS, may not be part of the language. (I'm not saying anything about the C standard [that I don't know]. Just a comment in principal.) > What's slightly weird about > it is that it can be defined in (at least) two different ways, > with or without argc and argv. Frankly, I have no idea about the details of evolution of the C language. The old K&R source I have I had considered a pain; it provoked more questions than giving answers. And since then C changed a lot. That's why I stay mostly conservative with C and if in doubt check things undogmatic just with my compiler. > [...] > >> If I want a defined exit status (which is what I usually >> want) I specify 'int main (...)' and provide an explicit >> return statement (or exit() call). > > Why would you ever not want a defined exit status, given that it's > easier to have one than not to have one? Aren't we agreeing here? (The only difference is that you are formulating in a negated form where I positively said the same.) > (Since C99 an explicit > return or exit() is optional.) I can't think of any reason *at all* > to use "void main" in C with a hosted implementation. Can you? Well, to indicate that there's no status information or that it's irrelevant. E.g. as was the case in the test fragment I posted. In programs I typically write there's a lot things that can possibly go wrong - and that the program cannot fix -, mostly (but not exclusively) externalities. So it's typical that I interrogate return status of functions, map them to a defined set of return codes, create own codes for data inconsistencies etc. And this status is relevant and of course returned to the environment (often accompanied by some textual information on stderr). > (If you don't care about the exit status, you can just write > "int main" and not bother with a return statement or exit() call. > The exit status will be 0, but that's not a problem if you don't > care about it.) Whatever current C standards - and I'm not sure what ancient 'cc' is on my system and to what standard it complies - say, if I specify an 'int' return type I also want a 'return' (or exit()) - consider it as "code hygienics" - even if it's not necessary according to more recent standards. Janis