c++ - Does C4800 have any real world value? -


the c4800 warning in microsoft c++ compiler described here:

https://msdn.microsoft.com/en-us/library/b6801kcy.aspx

makes code:

// c4800.cpp // compile with: /w3 int main() {   int = 0;   // try..  // bool = 0;    bool j = i;   // c4800   j++; } 

throw c4800 warning: "'type' : forcing value bool 'true' or 'false' (performance warning)"

microsoft seems think it's reasonably important, , has level3 warning, clang apparently think it's not, has 0 complaints @ -weverything, maximum warning level.

is there real world bug can come c4800 point out make worth having enabled?

basically, warning you've converting other integer type bool, , conversion isn't entirely free.

it's present (at least see things) warn you're mixing bools other integer types, not leads minor reduction in performance, may indicate confusion in code. looking @ code in question:

  int = 0;   // try..  // bool = 0;    bool j = i;   // c4800   j++; 

...what have looks incomplete conversion of code defined j of type int. definition of j has been edited it's of type bool, we're still assigning value int, , (worse) using post-increment on it, both of make sense if j had type int, don't j having type bool.

so, question whether wanted assign j result of comparison: bool j = (i != 0); or maybe more complete conversion turn i bool well:

bool = false;  // ... bool j = i; // no warning  j = true;   // cleaner way of producing same result post-increment. 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -