Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#209 closed defect (invalid)

svd_test uses operator|=

Reported by: Peter Owned by: Jari Häkkinen
Priority: trivial Milestone: yat 0.3 (Public release)
Component: test Version:
Keywords: Cc:

Description

In svd_test there are code like

bool testfail=false;
testfail |= test_something();
testfail |= test_something_else();
return testfail;

operator=| performs a bitwise operation, which is not really what is intended here. Obviously it is not a problem as long as bool false only contains zero bits, which is the case I guess. But should one really rely on such an assumption?

Change History (5)

comment:1 Changed 15 years ago by Jari Häkkinen

And in vector_test.cc we have

ok &= (vec.size()==vec2.size());
ok &= (vec2==vec);
ok &= (&vec2 != &vec);
ok &= !vec2.isview();

All these rely on the fact that false is all bits zero however a boolean false is represented. Remember that all values != 0 are true in a boolean sense. So, I cannot imagine a day in the future (for a properly designed operating system) where a bit could be non-zero for a false boolean value. There is no assumption made about the boolean 0 (false).

comment:2 Changed 15 years ago by Peter

Sure, I agree it is a tiny problem that should not cause any problem. It is more a question of style. Should one use bitwise operators when not working on bits?

There is actually an extra assumption in you code snippet. There we assume that bool true always is represented by the same byte. Sure I guess it is represented as a char 1, but OTH I have not read the chapter on why bool is needed.

comment:3 in reply to:  2 Changed 15 years ago by Jari Häkkinen

Replying to peter:

Sure, I agree it is a tiny problem that should not cause any problem. It is more a question of style. Should one use bitwise operators when not working on bits?

There is actually an extra assumption in you code snippet. There we assume that bool true always is represented by the same byte. Sure I guess it is represented as a char 1, but OTH I have not read the chapter on why bool is needed.

I agree, it is a question of style. There will always be questions of style when several people contribute to code.

Which bit represents what is not an issue here. If you follow the logic of the tests in svd_test or vector_test, the only interesting case is when one error happens, this sets the state of the test. If one error occur this will be reported when the program ends. In principle, the program could exit directly after the first encountered error, but our style of doing tests is to perform all tests before reporting success/failure.

The underlying representation of bool does not come into play here. The way to catch reports of test failures in the two programs will not fail now, nor in the future.

Instead of a lengthy discussion of assumptions made, what should be done to improve the functionality of the programs?

comment:4 Changed 15 years ago by Peter

Resolution: invalid
Status: newclosed

I say no more.

comment:5 Changed 15 years ago by Peter

Milestone: later0.3 (Public release)
Note: See TracTickets for help on using tickets.