Boost logo

Boost Users :

From: Paul Giaccone (paulg_at_[hidden])
Date: 2005-11-10 04:40:10


Robert Ramey wrote:

>Paul Giaccone wrote:
>
>
>>For booleans, though, a value of other than 0 or 1 means it has not
>>been initialised, and perhaps this should throw an exception on
>>writing to the archive rather than on reading from it.
>>
>>
>
>Hmmm, I'm not sure about this. Do we know for a fact that a bool variable
>will always contain 1 or 0? I've never seen code trap on an un-initialized
>bool. It seems that even an uninitialized bool corresponds to true or
>false.
>
>
Is requiring the value to be 0 or 1 part of the C++ ANSI standard?

If you want to try to reproduce the error, the code threw an exception
on an object that was allocated on the heap and contained a boolean,
which I had not initialised.

>Perhaps part of the problem is that I used 0 and 1 for bool variable
>in order to not included english strings "true" and "false" in text files
>and to save space.
>
>
This makes sense because 0 and 1 are probably what users would expect.
Is it however possible to do the equivalent of boolalpha on the stream
in order to write and read booleans as strings?

>I'll think about this.
>
>Robert Ramey
>
>
>
>>If handling uninitialised variables is not practical, then perhaps
>>there could be a warning in the documentation that uninitialised
>>booleans will cause stream errors on deserialisation.
>>
>>Paul
>>
>>


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