Bart said:
Bart said:
The key is not to detect overflows. Â The key is to understand the domain
You're ignoring bugs. Overflow detection (of the automatic kind) can
be a useful tool in a debug version of an application, in the same way
that array bounds checking can be.
And then you can turn off the checking for the production version of
the code.
Like a parachute that's only for use in the flight simulator.
No, more like a diagnostics box that tells you why you crashed or that
you were in danger of crashing.
I'm starting to understand Jacob's frustration at a group that either
completely dismisses the idea of this check, or proposes impractical
'standard C' versions of the checking code.
I don't understand this frustration. I don't think the idea has been
"completely dismissed" by this group and a portable C check might be useful for
people who don't have any other option.
Were I to propose language feature "X", the useful replies will be
among the critical ones. Sure, it is nice to get a ringing
endorsement of one's ideas, but such an endorsement does not help get
anything into the C standard. If I have not thought of a problem that
is pointed out, or not considered an alternative mechanism that
someone suggests, then I will be glad to be better informed. And if I
have been round that design loop, I am no worse off. Some of critical
responses might be useful, but none of the positive ones are.
If Jacob's objective is to get something into C, then most of the
negative feedback is useful because it will surely come at some point
in shepherding the proposal though. If he wants the best overflow
detection in his compiler, then seeing alternative proposals might be
useful. If he is sure that he already has the best possible design,
what does he care what lesser thinkers think?
I agree overflow checking is not very exciting, and only catches a
small class of errors (eg. overflow of A*B, due to A or B having the
wrong value, but A*B can also give a wrong value that doesn't
overflow). But it can't do any harm to have it available as an extra
tool.
Absolutely not. It could be harmful, however, to have things in the
language standard that are not well designed. I am not commenting on
this specific design. My impression is that most people agree that it
is a good idea (in general) but they disagree on how best to reflect
the feature in the language.
I mentioned elsewhere that I applied my own overflow check inside an
interpreter. Suppose that code (the code responsible for executing "A
+B" for example) was written in C, and I wanted to use the signed
overflow check to switch to a wider int datatype.
What's the best way of doing that in C at present, bearing in mind
that integer addition has to be kept as fast as possible, so using the
14-term expression proposed by Richard Heathfield is completely out of
the question?
(I'm only interested in running on x86-family processors, since those
are the only ones I can buy.)
You already know the best way to do it. If you need a single portable
solution then a manual check is the only way so it can't be "out of
the question". If you can make do with, say, Jacob's compiler then
you already have the solution, so why consider anything else? If you
need to do it on multiple implementations of C, then you have no
choice but to see what they all offer and use implementation-specific
code for each one. You know this.
No one is saying that this is the best option, but it is disingenuous
to suggest that people here are blocking a good idea that would
otherwise solve a real-world problem you have.
You won't get a compiler that conforms to the next C standard for many
years and it will be even longer before you can rely on the standard
for a widely portable solution. Furthermore, I can't image that
anything said here will have the slightest adverse effect on whether a
proposal from Jacob gets accepted or not. Comments here may help to
improve any proposal that he puts forward (by, for example, bring up
cases he has not considered) but it will stand or fall on its merits,
not on the reception it gets on c.l.c.