Sujet : Re: Whaddaya think?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 18. Jun 2024, 06:09:34
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4r4qg$16pi5$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
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"); }
- 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.
If the
exit status is undefined, it might be a failure status. In many
contexts, that would cause no problems, but there's also places where it
would.
Exactly.
...
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.
That's the problem - your "indication that there's no status
information" doesn't achieve the desired effect. Instead, it results in
an unspecified status being returned to the system. If might be a
successful status, or an unsuccessful status. On the systems I use,
scripts that execute programs will often abort if the program returns an
unsuccessful status code. If there's nothing that needs to be brought to
the system's attention, use "return 0;", not "void main()".
In cases where the return status is a substantial part of the
external specification, yes. Return status is not self purpose!
YMMV.
Janis