John Bates
unread,Sep 5, 2012, 11:18:44 AM9/5/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to qf...@google.com, chromi...@chromium.org, jam...@google.com, Nico Weber, Fred Akalin
On Wed, Sep 5, 2012 at 1:42 AM, Piotr Kufel <
qf...@google.com> wrote:
>
>> Has this warning always been enabled? Or, is it new with VS2010?
>
>
> I recall it was present in 2k8 too.
>
>> I assume it doesn't impact expressions like "if (foo_ptr) {..."?
>
>
> AFAIR it's a performance warning: I think C++ semantics require bool to be
> stored as 0 or 1
Note: the spec does not specify how bool is stored in memory, but when
cast to int, the spec says false becomes 0 and true becomes 1.
> , so (int)(bool)2==1 - it introduces compare/branch in a
> simple integral type cast.
Most CPUs have a select instruction, so I would be surprised to see a
branch. Have you seen this code become a branch in practice?
> In case of if (expr) you don't have a way to
> access the boolean value of expr later, so there's no warning because the
> compiler can just test for expr being nonzero without physically storing the
> result in one-byte 0/1 value.
>