M
Mike Wahler
Howard said:
Funny, but a bit ludicrous, Mike.
Not at all.
If I buy a chain saw, I know it has the
capability to cut off my hand (or anything else) if I abuse it. After all,
it is DESIGNED to cut things off!
And the C language is designed to perform its task 'safely',
*if used according to instructions*, just like a chain saw.
The consequences of misuse, whether intentional or inadvertent,
cannot be reasonably blamed upon the manufacturer of either.
However, writing a compiler that
translates the standard's meaing of "undefined behavior" into "I can format
his hard drive if I want" is an act of malice, or at least negligence,
That is not what I said. "Undefined behavior" by definition,
is *undefined*. There is no 'translation'. The language
definition, when it indicates that its misuse results in
undefined behavior, it is essentially saying 'out of my
hands', I'm no longer responsible for the behavior of the
program. The language definition *specifically identifies*
which such misuses fall into this category. I.e. *you've
beeen warned.*
E.g. if language misuse results in an OS getting a spurious
'instruction' to format a disk, set the monitor on fire or
whatever, one cannot reasonably blame the manufacturer
or vendor of the language implementation.
"Intentional" behavior is by definition, 'defined'.
and
would definitely be actionable in a court of law (and probably not just in
the US either).
You're assigning meaning where there is none.
Do you write programs that, if the user does not read and
understand your user's manual correctly, will format their hard drive?
Of course not. You're missing the point.
If
so, please let me know what products you produce so I can avoid them!
Here, run this:
int main()
{
int i;
if(i == 42)
++i = i++;
return 69;
}
As a side note, the reason I brought this up is that that statement about
formatting someone's hard drive when undefined behavior is invoked is used
quite often in this newsgroup, but is, in my opinion, very misleading.
I don't think so. I think it's a good way to convey an
example *possible* serious consequence of undefined
behavior. IMO many will of course naturally dismiss
the ubiquitous 'nasal demons' example as simple
facetiousness. An example of a real catastrophe
is imo more representative of possible consequences
of undefined behavior, and imo is a better incentive
for being careful.
If you get into your car, put it in gear, close
your eyes, and open the throttle, the consequences
will be "undefined". E.g. nothing bad might happen,
or you might end up killing several people. The
manufacturer of the car cannot rationally be held
responsible (except of course in U.S. courts. ).
I've never seen a car's owner manual specifically
warn against driving without watching where you're
going.
circumstances.The
standard may state that a specific type of coding constitutes undefined
behavior under the standard, but that does NOT mean anyone actually writes
compilers that take malicious or bizarre actions under those
You miss the point. Such actions will not be those of the
compiler, but of entites and/or circumstances which *by
definition*, are outside its control.
Compiler writers have customers that must be satisfied, and some (if not
all) of those customers are BOUND to make mistakes sometimes.
And these mistakes are the responsibility of the *user*,
not of the maker of the misused product.
It is an
imperative that they take at least "reasonable" actions when undefined
behavior is encountered
By definition, undefined behavior, is *undefined*,
*outside the control of the compiler*.
I can ask you "If you're standing on a balconey above
a crowd, holding a knife, and drop the knife over the
rail, what will happen?"
What will you answer? Probably something like "Someone
might get hurt." So I tell you, "the consequences cannot
be known, although there's a good probability that something
bad will happen, so be careful, and of course don't do it
intentionally." So you somehow inadvertently drop the knife,
injuring or killing someone. Will you blame the manufacturer
of the knife?
(assuming that they understand and can detect those
conditions in the first place).
Here's where your argument really falls apart. *Undefined*
implies "cannot predict the outcome."
Failure to do so will lose them customers,
and money, FAST!
Yes, intentional malice should cause loss of business,
and possibly legal action. But what you're saying is
like saying that your boat's manufacturer is responsible
when it sinks or capsizes because you've overloaded it,
disregarding any warnings about such in its owners manual.
(Now, if there are any compiler WRITERS out there that
disagree, please let us know. )
I think any rational person will disagree with your
argument.
How about, when telling posters about the meaning of "undefined behavior",
Please look up the dictionary meaning of 'undefined'.
You'll see something like "unknown", or "with no meaning".
So what could possibly be the "meaning" of something
without meaning?
we leave it at that,
I rarely leave unfounded or incorrect assertions 'at that'.
and don't insinuate (or outright state) that they're
going to lose their hard drive
Nobody said they *will*, we (accurately) say they *could*,
and advise caution.
if they make a mistake, ok?
We're trying to convey the possible serious consequences
of such mistakes. Since "undefined behavior" means
*anything* can happen, of course this includes catastrophe,
as well as no problems at all. IMO it would be irresponsible
to *not* warn about this.
-Mike