Sujet : Re: Whaddaya think?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 18. Jun 2024, 10:57:12
Autres entêtes
Organisation : None to speak of
Message-ID : <87v826zi87.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> writes:
On 17.06.2024 15:38, James Kuyper wrote:
On 6/17/24 03:16, Janis Papanagnou wrote:
On 17.06.2024 08:20, Keith Thompson wrote:
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
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.)
You implied, by saying "If I want a defined exit status", that there are
occasions where you don't want a defined exit status
>
...where I don't _need_ one. Yes.
E.g. in code like main() { printf("hello, world\n"); }
That's been a syntax error since C99, which dropped the "implicit
int" rule. (Some compilers accept it by default to cater to old
code, if you don't ask them to enforce the current language rules.)
- and he's
questioning that. Things that are undefined are seldom useful.
>
I disagree. If things are undefined it _may_ just not matter.
If things matter they should not (ideally never) be undefined.
But you have to go out of your way to make it undefined, by
violating the rules of the language. Why would you do that?
Sheer stubbornness?
In C90 and earlier, falling off the end of main caused an unspecified
exit value, which seems to be what you want for some reason.
In C99 and later, there is no valid way to do that.
<
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>
is a draft of the 2011 ISO C standard. Section 5.1.2.2.1,
"Program startup", covers what we've been discussing about main.
One more thing to know is that if a requirement uses the word
"shall" outside a constraint (such as the "shall" in paragraph 1),
violating that requirement causes undefined behavior.
You've gotten the idea, based on a badly out of date book, that C
gives you a way to leave the exit status unspecified. It doesn't.
[...]
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */