Sujet : Re: Whaddaya think?
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 18. Jun 2024, 08:25:59
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4rcq7$17pq5$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Mozilla Thunderbird
On 6/18/24 01:09, Janis Papanagnou wrote:
On 17.06.2024 15:38, James Kuyper wrote:
...
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.
I was merely directly addressing your comment by pointing out that the
status returned was unspecified. While technically correct that's like
saying that a nuclear bomb could be used to light a match. It's
unspecified because, as Keith pointed out, the behavior of the entire
program is undefined.
Is there anything that a program could be written to do on your computer
that you would not like it to do? The C standard imposes no restrictions
on the behavior of a program created by translating code that has
undefined behavior, so a fully conforming implementation may legally
translate such code into a program with that behavior. If the
implementation you're using documents what it does with "void main()",
you can rely upon that documentation - but do you know for a fact that
it does document it?
When you deliberately write a program that you know to have undefined
behavior, what you are, in effect, telling the implementation to do is
create an executable that has any behavior it wants to give you. If
that's OK with you, there's no need to write a new program. Any existing
program already has behavior that your such code could legally be
translated to, so you might as well just execute any arbitrary program
that's already been translated, and save yourself some time.