Sujet : Re: Two questions on arrays with size defined by variables
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 10. Feb 2025, 19:33:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vodgqk$1b1u0$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 10.02.2025 07:57, Keith Thompson wrote:
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
[...]
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).
I'm with you.
Personally I think it's an uninteresting point; primarily because
it's a detail and, as you wrote, also a special case.
I would prefer - but for that reason of minor importance to me I
also don't mind as it is - if the language would allow all sorts
of interface variants, e.g.
void main (void) { ... } or also void main () { ... }
int main (void) { ... ; return rc; }
void main (int argc, ...) { ... }
int main (int argc, ...) { ... ; return rc; }
if they are _consistent_; i.e. no 'return' allowed in case of a
void declaration (with an implicit return 0 to the environment),
and requiring an explicit 'return' in case of an int declaration.
What I find bad is if some special [visibly inconsistent] form
is the norm and other [more consistent] forms are "UB" with the
"threat" of the proverbial missile launch as possible outcome.
I haven't checked what's actually valid in current or former
"C" compilers or standards. As it's of minor relevance (to me)
I just see whether the compiler accepts my main() declaration
or not. (There was never a problem here, so why should I care.)
Janis