On Jul 4, 10:25 pm, Mike -- Email Ignored <
[email protected]>
wrote:
[...]
I used the usual options that I use for compiling production code:
-std=c++98
-ffor-scope
-fno-gnu-keywords
-foperator-names
-pipe
-Wall
-W
-Wno-sign-compare
-Wno-deprecated
-Wno-non-virtual-dtor
-Wpointer-arith
-Wno-unused
-Wno-switch
-Wno-missing-field-initializers
-ggdb3
-D_GLIBCXX_CONCEPT_CHECKS
-D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC
They're not complete (I forget why we don't have -pedantic in there),
but they're a start.
You use many more options than I do. Are all these really necessary?
They were at one time, in the context I was working. Options
are a lot like includes: you add them when you need them, but
they don't get removed if the cease to be necessary
. Also,
-pedantic is generally recommended, but I don't have it. I do
remember having it once, but I forget why I removed it. (I
think it was because -pedantic turned off support for long long,
which I need, even if it isn't currently part of C++. But I
also seem to recall having seen recently that there is a
separate option which can be used to control this, overriding
-pedantic.)
Typically, however, I'd say that that list is about average for
what you need with just about any compiler.
[...]
Except that you want an abort, not an exception. (The
problem isn't cases where there is uncertainly. Uncertainty
can be removed by means of an if. The problem is where your
certitudes turn out to be wrong.)
Why an abort rather than an exception? I would think that it
depend on the application.
It's a programming error. Something which can't happen, but
did. In such cases, you can no longer make any assumptions
concerning the state of the program, and the best thing you can
do is to terminate as quickly as possible, executing as little
code as possible.
And yes, it does depend on the application. That's a more or
less general rule, which leans toward safety and robustness; in
some cases, however, if an error goes unnoticed, it's not an
error, and whether it's noticed immediately or an undeterminate
moment downstream doesn't matter. (A typical case might be
games programming.)
For certitude, consider things like:
std::vector<int> vec;
...
for (int jj = 0; jj < vec.size(); ++jj)
cout << vec[jj] << endl;
I first went through the code and changed all [] to at. Then
I looked back and saw things like the above fragment, and
decided I was being ridiculous, and throwing away cycles for
nothing.
What cycles are you throwing away. In one case, the library
code verifies the index, and then aborts, and in the other, it
verifies the index, and then raises an exception. In a well
written library, with normal options, you execute the if, and
nothing else, in either version. (And of course, a good
compiler can, and probably should, recognize that the if can
never fail, and suppress it.)