Re: void * instead of bool
From: John Harrison (john_andronicus_at_hotmail.com)
Date: 06/21/04
- Next message: Min-Koo Seo: "Re: Does anyone has fixed size memory allocator code?"
- Previous message: Mike Wahler: "Re: Interview questions"
- In reply to: Marcin Kalicinski: "void * instead of bool"
- Next in thread: Rolf Magnus: "Re: void * instead of bool"
- Reply: Rolf Magnus: "Re: void * instead of bool"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 21 Jun 2004 16:07:26 +0100
"Marcin Kalicinski" <kalita@poczta.onet.pl> wrote in message
news:cb6t4d$p0l$1@korweta.task.gda.pl...
> Hi,
>
> Why is there void* conversion to check for std::istream failure bit? Why
not
> a conversion to bool?
If you have a conversion to bool then the following nonsense would compile
float f = cin;
Conversion to void* is less likely to be called accidentally.
>
> 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.
You could do this
return some_stream.good();
>
> Is there any reason to avoid automatic conversion to bool and prever
> conversion to void* instead?
>
See above.
> Marcin
>
>
john
- Next message: Min-Koo Seo: "Re: Does anyone has fixed size memory allocator code?"
- Previous message: Mike Wahler: "Re: Interview questions"
- In reply to: Marcin Kalicinski: "void * instead of bool"
- Next in thread: Rolf Magnus: "Re: void * instead of bool"
- Reply: Rolf Magnus: "Re: void * instead of bool"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|