Re: nullptr == p_one_past_last
Frederick Gotham wrote:
kanze posted:
For that matter, formally: overflow is undefined
behaviour.
If numeric_limits<int>::modulo is true, then is overflow
well-defined?
That's a very good question. All the standard seems to say is
that "a type is modulo if it is possible to add two positive
numbers and have a result that wraps around to a third number
that is less." (Less than what: the real result, or one of the
original two numbers?) I'm not sure what the formal definition
of "wraps" is: would an implementation which always gave a
result of 0 on overflow be "modulo". (I suspect that the intent
is that the results be well defined on a specific machine. And
that the results would be what one normally expects by "wrap".)
For instance, does the following code exhibit
undefined behaviour?
#include <climits>
#include <limits>
int main()
{
int i = INT_MAX;
if (std::numeric_limits<int>::modulo) i *= 5;
}
Again, who knows? I would say yes, on the grounds that you can
have hardware which wraps for add and subtract, but generates a
trap for multiply and divide.
Personally, I find the current definition a bit useless: to be
useful, you'd need a finer definition of "wraps", and you'd need
to specify that it applies to all arithmetic operands (including
unary minus!). Or you can say that it should only be true if
the implementation specifies (and guarantees) what it means.
--
James Kanze GABI Software
Conseils en informatique orient9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S9mard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]