M
Marcin Kalicinski
Hi,
Why is there void* conversion to check for std::istream failure bit? Why not
a conversion to bool?
When I try to return an istream from a function that actually returns bool,
I get the following warning (in VC .NET):
warning C4800: 'void *' : forcing value to bool 'true' or 'false'
(performance warning)
I can get rid of it by returning (stream != 0) or (!!stream), but it looks
ugly to me. Besides that, I suspect that it might perhaps be generating
unoptimal code. Compiler does not know that void* value holds only 0 or 1 in
the case of streams, and adds extra code to prevent the value going out of
bool range. At least that's what the warning is trying to say.
Is there any reason to avoid automatic conversion to bool and prever
conversion to void* instead?
Marcin
Why is there void* conversion to check for std::istream failure bit? Why not
a conversion to bool?
When I try to return an istream from a function that actually returns bool,
I get the following warning (in VC .NET):
warning C4800: 'void *' : forcing value to bool 'true' or 'false'
(performance warning)
I can get rid of it by returning (stream != 0) or (!!stream), but it looks
ugly to me. Besides that, I suspect that it might perhaps be generating
unoptimal code. Compiler does not know that void* value holds only 0 or 1 in
the case of streams, and adds extra code to prevent the value going out of
bool range. At least that's what the warning is trying to say.
Is there any reason to avoid automatic conversion to bool and prever
conversion to void* instead?
Marcin