Sujet : Re: Whaddaya think?
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 17. Jun 2024, 14:38:54
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4pe9e$lpi6$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13
User-Agent : Mozilla Thunderbird
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:
...
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.
K&R C did not have function prototypes. main() declared with no
arguments indicates that main takes an unknown number of arguments, of
unspecified type - as such it's compatible with taking either two
arguments, or none. For backwards compatibility, you're still allowed to
declare functions K&R style, but it's been more than 3 decades since it
was a good idea to do so.
...
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 - and he's
questioning that. Things that are undefined are seldom useful. 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.
...
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()".