Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Two questions on arrays with size defined by variables Date: Sun, 09 Feb 2025 22:57:06 -0800 Organization: None to speak of Lines: 52 Message-ID: <878qqep9rx.fsf@nosuchdomain.example.com> References: <878qqf1kl2.fsf@nosuchdomain.example.com> <877c5yr5vv.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Mon, 10 Feb 2025 07:57:07 +0100 (CET) Injection-Info: dont-email.me; posting-host="f4acd3ba793eeb2facf0b27d62bf5cd0"; logging-data="1134682"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KebHFym2dUnWHnyEJ5nlm" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:LLod29XDsMrxF7Kt6vme1BZvJhM= sha1:SIHRazhGfV0FQ4J+/S4j8KI5NoA= Bytes: 3545 Janis Papanagnou writes: > On 10.02.2025 05:14, Andrey Tarasevich wrote: >> On Sun 2/9/2025 6:35 PM, Janis Papanagnou wrote: >>>> The "return 0;" is unnecessary but harmless in C99 and later. >>> >>> That - returning a value when a function is declared to return >>> one - is actually a [maybe picky] coding-habit of mine. :-) >> >> This is, of course, a purely stylistic matter. But still... `main` is >> special. > > I know. > >> And it kinda makes sense to acknowledge it special nature by >> not doing explicit `return 0` from `main`. `main` looks cleaner without it. > > Now I'm astonished by that comment (to say the least). > > I'm regularly returning status and error information to the calling > instance to act upon it. And you're saying that I should not return > any value? Or only values that are different from 0? Or only 0 if I > also return other values? - Whatever; that sounds all wrong to me. > Or is 'return' deprecated or depreciated and we should now rewrite > our source code and replace every 'return' by 'exit()', or use now > only 'exit()' in the first place instead? > > I don't think you will convince me to not return 0 only because in > the special case that there's nothing specified the current language > standards defines that per default it implicitly provides that value > for me. Having a "return 0;" at the end of main() is neither obsolescent nor deprecated. It's still perfectly valid, with the expected semantics. The only that changed in C99 is that reaching the closing "}" of the main function does an implicit "return 0;". This change was borrowed from C++. I do tend to dislike the change; it feels like an unnecessary special case, and I used to advise people to add an explicit "return 0;" anyway. This was partly because C99 compilers were relatively rare, and there were advantages to writing code that still worked with C90-only compilers. I usually omit the "return 0;", but I don't object to including it -- though I will occasionally mention in passing that it's "unnecessary but harmless". If nothing else, the history is interesting (at least to me). -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */