|
Boost Users : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2005-11-10 13:47:30
Nigel Rantor wrote:
> If Robert can find a nice way of trapping uninitialised variables (not
> simply bools of course) and throw exceptions for these then that's
> great. I'm not sure that is entirely possible though. (and I haven't
> psent any time thinking about it either)
>
I checked my reference on the subject of bool/int conversion. This is
Section 4.2 Booleans in "The C++ Programming Language by Stroustrup.
I see that "in arithmetic or logical expressions, bools are converted to
ints...
if the result is converted back to bool, a 0 is converted to false and a
non-zero value is converted to true".
Looking at the above and having considered the postings on the thread
my inclination is to do the following:
* when booleans are output, booleans are converted to integers and
an assertion is thrown if the resulting value is other than zero or one.
This is in line with my view of trapping a program as soon as possible
when any kind of programmign error has been detected.
This naturally suggests the following for floats and doubles.
* any attempt to save floats or doubles for which the result of isnan(..) is
false
will trap with an assertion.
This would be a good thing from my standpoint as up until now a NaN
could be saved but not recovered as the standard text stream input
chokes on the Nan Text. Meanwhile the binary input just loads the
bits whatever they were. This conclicts with my goal of making
all archives behave alike.
I'm concerned that someone standup and show "But NaN is a valid value
for a float or double and I should be able to serialize that!!!". I'm
inclined
to reject this characterisation basically because doing so will make
my life easier. This will trap some user's errors at the cost of
prohibiting
some behavior that could be defended as correct.
Now I have one more damn problem. Some compilers (vc, bcb 5.51) use
_isnan(...)
while others (gcc) use isnan(...). Including <cmath> doesn't help here
because
it doesn't include isnan. Of course I can handle this with the #if/endif
blunt
instrument but if anyone has a better idea I would like to hear it.
Robert Ramey
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net