|
-
March 14th, 2009, 09:46 PM
#1
forcing value to bool 'true' or 'false' (performance warning)
I'm perusing source code (code I didn't write but I'm now trying to maintain) that has a litany of get and set methods within various message classes. The get methods within these class return - for the most part - enumerated types (and there's lot of flavors) or unsigned short.
The values of the get methods is then stored into a 'bridge'. Trouble is, the bridge class has a mix of unsigned shorts and bool as types. This was done to keep things 'generic'. IOW: The bridge shouldn't care about enumerated types.
For simplicity here's a contrived example:
Code:
# include <iostream>
enum Overall_Status
{
Overall_Status_UNUSED = 0,
Overall_Status_PASSED = 1
} ;
class test {
unsigned short x ;
public :
test( unsigned short x_ )
: x ( x_ ) {}
Overall_Status GetMethod () {
return ( static_cast < Overall_Status > ( x ) ) ;
}
};
int main() {
test f ( 1 ) ;
bool xx = f.GetMethod ( ) ; //[1]
unsigned short yy = f.GetMethod ( ) ; //[2]
Overall_Status zz = f.GetMethod ( ) ; //[3]
std::cin.get();
}
Alas, I'm now faced with 384 warnings I have to fix. Warnings akin to the one shown above via item [1]. i.e:
warning C4800: 'Overall_Status' : forcing value to bool 'true' or 'false' (performance warning)
My solutions thus far (can't muck with the return types on the messages):
a) use an unsigned short (2 bytes on the implementation - so I use an extra byte - bool is 1 byte on the implementation) -- see [2] above
b) Modify the bridge types to match the types in the message classes -- see [3] above
c) ??????? <not sure>
Thoughts!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|