Compiler warning C4800: 'type' forcing value to bool 'true' or 'false' (performance warning) #4825

pull ENikS wants to merge 1 commits into bitcoin:master from ENikS:C4800_fix changing 9 files +23 −23
  1. ENikS commented at 12:11 AM on September 3, 2014: contributor

    This warning is generated when a type value that is not bool is assigned or coerced into type bool. Typically, this message is caused by assigning int variables to bool variables where the int variable contains only values true and false, and could be re declared as type bool. Ii is generally recommended to add "(0 != X)" to the expression, which gives the expression the type bool.

    For more info see: http://msdn.microsoft.com/en-us/library/b6801kcy.aspx

  2. TheBlueMatt commented at 5:37 AM on September 3, 2014: member

    Generally looks good, though I'm not such a fan of the yoda conditionals. Also, the extra parenthesis on many lines makes it harder to read imo.

  3. laanwj commented at 10:12 AM on September 4, 2014: member

    Agree on the yoda conditionals. We don't use this anywhere, so let's not start introducing them.

  4. jgarzik commented at 12:22 PM on September 4, 2014: contributor

    Indeed -- please make the code look like other bitcoin code. We never use "(0 == ...)".

  5. ENikS commented at 10:56 PM on September 4, 2014: contributor

    Personally I consider not using yoda conditionals in C and C++ poor coding style. If you work for heavy C++ coders like Hughes or IBM you would be frowned upon for that. But if you insist, have it your way...

  6. jgarzik commented at 11:37 PM on September 4, 2014: contributor

    The even-more-universal rule applies: Your code should look like the code around it. This applies to any codebase. In this case, your code should look like bitcoin code, not IBM or Hughes code. :)

  7. ENikS commented at 12:06 AM on September 5, 2014: contributor

    @jgarzik If code does not follow good practices and coding standards it should be improved. Should I mention not being able to build release variant because of assert()? Lets face it, BC could benefit from some code improvements.

    It is kind of strange to hear about shortage of developers supporting core dev for btc on each and every conference and being snubbed by the team when this help is offered on the grounds that codding "good practices" go against personal preferences.

  8. luke-jr commented at 12:09 AM on September 5, 2014: member

    Coding style preferences, even Hughes or IBM's, are not "good practices".

  9. ENikS commented at 12:16 AM on September 5, 2014: contributor

    @luke-jr Yoda conditionals are. Anyway, I see no point in picking fight. I've changed code as requested.

  10. sipa commented at 12:21 AM on September 5, 2014: member

    Nobody will claim that the source code is perfect. There are many improvements possible, and all help is welcome (though the bottleneck is testing and reviewing).

    Still, please respect that each code base has its own style, and that that is really just a convention.

    WRT Yoda conditions specifically: there once was a good reason for them (avoiding accidental assignment when you wanted a test), but every compiler nowadays will warn you for that anyway. To anyone familiar with this code now, it just looks confusing. BTW: I don't think I ever saw a Yoda condition in the Google code base.

  11. sipa commented at 12:24 AM on September 5, 2014: member

    Thanks for changing it :)

  12. rebroad commented at 6:18 AM on September 5, 2014: contributor

    Does this need to be 5 commits or can they be merged into one?

  13. in src/util.cpp:None in a1104a6ac1 outdated
     493 | @@ -494,7 +494,7 @@ bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
     494 |  {
     495 |  #ifdef WIN32
     496 |      return MoveFileExA(src.string().c_str(), dest.string().c_str(),
     497 | -                      MOVEFILE_REPLACE_EXISTING);
     498 | +                       MOVEFILE_REPLACE_EXISTING) != 0;
    


    rebroad commented at 6:19 AM on September 5, 2014:

    extraneous space


    sipa commented at 8:21 PM on September 5, 2014:

    And rightfully so; the indentation was wrong...

  14. ENikS commented at 3:11 PM on September 5, 2014: contributor

    Now that everyone seams to be happy. Squashed.

  15. laanwj commented at 3:52 PM on September 5, 2014: member

    I've worked on various C and C++ projects for companies and never saw 'yoda conditionals' in serious use. I have seen my share of other (sometimes crazy) "let's use this coding style to avoid bugs" initiatives though, so I've seen where you're coming from. However there is no evidence that religiously insisting on a certain coding style actually avoids bugs. Usually these were projects riddled with bugs because the developers at the organization spent all their time writing reports and checklists instead of paying attention to the code.

    Anyhow -- thanks for showing some flexibility and changing this. One final nit: the commit message, "Squashed all into one" is funny but says little :)

  16. sipa commented at 8:22 PM on September 5, 2014: member

    Untested ACK

  17. ENikS commented at 10:43 PM on September 5, 2014: contributor

    Why is it failing now, there are no changes been made? Is there a way to re run the check other than to make new commit?

  18. theuni commented at 10:55 PM on September 5, 2014: member

    @ENikS false negative

  19. TheBlueMatt commented at 11:29 PM on September 5, 2014: member

    ut ACK

  20. sipa commented at 5:32 PM on September 6, 2014: member

    Oh, right; change the commit message to something meaningful, please.

  21. Fixing compiler warning C4800: 'type' forcing value to bool 'true' or 'false' 8d657a6517
  22. BitcoinPullTester commented at 5:21 PM on September 11, 2014: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4825_98fbd76868f8610a805da2566235e5b643f15434/ for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  23. sipa merged this on Sep 16, 2014
  24. sipa closed this on Sep 16, 2014

  25. sipa referenced this in commit dc54e9db98 on Sep 16, 2014
  26. ENikS deleted the branch on Sep 16, 2014
  27. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-18 21:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me