Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2005-11-10 11:21:42


"Robert Ramey" <ramey_at_[hidden]> writes:

> Nigel Rantor wrote:
>> Robert Ramey wrote: Pragmatic:
>> Well, how about simply treating anything other than 1 as false? I
>> realise this means that you are implicitly initialising someone
>> elses variable should they serialise and then deserialise but it
>> would seem to preserve the effect that you would witness should you
>> use such a variable without performing that set of operations anyway
>> so it would be an "invisible" side-effect.
>> Correct:
>> Initialise all your variables. Shoot all programmers who don't!
>> And of course, the one true way - tell everyone to initialise their
>> variables or bad things might happen and then be lenient on parsing
>> anyway.
>
> Actually, my preferred way would be to trap the usage of an
> unitialized bool variable when it is saved. Its not clear that I can
> do this.

No, of course you can't. An unitialized bool could look exactly like
an initialized one. And if it's uninitialized and you read it, you
could crash the program.

> But a close substiture might be to convert the variable to
> an integer, throw an exception if its not equal to 0 or 1

No!! If you convert a bool to an integer and get something other than
0 or 1 then there's a bug in the program (or in the compiler). An
assertion is appropriate.

> and serialize it otherwise.

Why all this talk of conversion to integers? I still can't understand
it. Why not just serialize the bool?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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