Compiler Warning C4018 'expression' : signed/unsigned mismatch #4824

pull ENikS wants to merge 1 commits into bitcoin:master from ENikS:C4018_fix changing 1 files +1 −1
  1. ENikS commented at 10:20 PM on September 2, 2014: contributor

    By default enum is a signed integer. It creates signed/unsigned mismatch mismatch if used in expression like this: return ((nStatus & BLOCK_VALID_MASK) >= nUpTo); --(Main.h - line 737)

    To avoid this condition making enum smallest unsigned type to hold all values 0 - 96 which is unsigned char. For more info please see this: http://msdn.microsoft.com/en-us/library/y92ktdf2.aspx

  2. luke-jr commented at 10:26 PM on September 2, 2014: member

    Sounds like a compiler bug. I'm surprised Bitcoin Core builds in MSVC at all.

  3. TheBlueMatt commented at 10:33 PM on September 2, 2014: member

    Looks like a legitimate "doesnt compile" with old gcc. @theuni should Travis not also run with such an old gcc to catch this?

  4. ENikS commented at 10:36 PM on September 2, 2014: contributor

    It builds quite well. I have list of warning to cleanup (4018;4101;4146;4999;4244;4267;4345;4503;4717;4786;4800;4804;4805;4996;) but otherwise it is fine.

  5. theuni commented at 3:52 AM on September 3, 2014: member

    @TheBlueMatt I'm all for adding different compilers in order to maintain portability (cleaning up the warnings from clang -Weverything could keep someone busy for months), but I don't see much utility in adding outdated compilers just so that we can see if we hit their bugs. If we're going to add different compiler configs, imo clang/msvc/icc would be more real-world useful.

    Unless, of course, there's a legitimate use for testing against broken/old compilers. LTS ppa toolchains, for example.

  6. TheBlueMatt commented at 5:40 AM on September 3, 2014: member

    @theuni I was under the impression the compiler on pull-tester's windows build was the same as the Ubuntu LTS's max mingw version?

  7. ENikS commented at 5:27 PM on September 3, 2014: contributor

    I am actually quite surprised you don’t target MSVC tool chain. There are a lot mere developers working with Visual Studio than with gcc in Windows. Cost of entry (in terms of learning and setup) is much smaller with VS IDE as opposed to all these cross compiler and since Windows still predominant OS on desktop you do the math. If wider adoption is a goal code should be buildable on VS so more people could jump in.

  8. theuni commented at 6:30 PM on September 3, 2014: member

    @TheBlueMatt Not sure about pull-tester. Travis uses the same as Gitian. @ENikS we don't target any toolchains, but we do test and support-ish some. Due to the nature of Bitcoin, most devs work in Linux, some in OSX, some in the BSDs, and few in Windows. Official builds must be created using an entirely free/open stack, including the toolchain. mingw is much easier to automate for c-i and deployments, so it's the obvious choice for us.

    However, there's no reason why the code shouldn't build under MSVC. Any build failure (assuming it's caused by non-conformant code as opposed to a MSVC quirk) is a bug and should be fixed.

  9. TheBlueMatt commented at 6:35 PM on September 3, 2014: member

    @theuni pull-tester uses the same that gitian used to, I suppose it was updated?

  10. ENikS commented at 6:53 PM on September 3, 2014: contributor

    @theuni Well, I guess my point was that it is about time MSVC be support-ish-ed as well as other compilers.

  11. laanwj commented at 12:33 PM on September 4, 2014: member

    @ENikS It's simple - there is no developer regularly building master on MSVC, so MSVC problems don't get caught. If you're willing to volunteer for that, you're welcome!

  12. ENikS commented at 5:03 PM on September 5, 2014: contributor

    If someone walks me through your automated build process perhaps I could help to set something similar for the msvc free tool set. Something like VS Express of MSBuild with SDK. I don't have much time, have to work for living but this would be worth some effort.

  13. laanwj commented at 5:49 PM on September 5, 2014: member

    I don't think the current build system (autotools + make) can use the MSVC compiler. What projects usually do is to have a parallel build system specifically for MSVC, i.e. by checking in a solution file. But it will be a maintenance burden to make sure that doesn't get out of sync when files are moved around. Maybe it would be possible to generate a MSVC solution file from the current build system somehow.

    I also know it's possible to call the MSVC compiler from WINE, so scripting to run it automatically on a linux host would be possible, which can make it a little easier for the other developers without windows to check it as well.

    Seems like quite some work, but if you think it's worth the trouble, why not.

  14. theuni commented at 5:53 PM on September 5, 2014: member

    @ENikS Not sure what you're getting at. We don't have an automated build process for msvc precisely because it's so different from the others. You'd be exploring new territory.

  15. ENikS commented at 6:04 PM on September 5, 2014: contributor

    You saying this territory would not be worth exploring? I know there are interest in Windows community but last two attempts at participation died because of luck of support (may be it is not dead but it has no updates, and I am not sure if either Claire DuSoleil or bc4-old-c-coder even asked for it). I think core should be available on windows as well as any other OS with native support and willing to help. I don't have much time because I have to work at my paying job so I can not volunteer for the entire effort but if someone would help with the environment I would provide msvc specific configuration.

    Code in present form builds and runs in Visual Studio so it would require no changes whatsoever.

  16. theuni commented at 6:09 PM on September 5, 2014: member

    @ENikS certainly not saying that. Only that it's new. I'd be happy to help and answer questions.

  17. ENikS commented at 6:15 PM on September 5, 2014: contributor

    @theuni Well, where would I download virtual machine with all the tools setup so I could just add one more?

  18. laanwj commented at 6:18 PM on September 5, 2014: member
  19. ENikS commented at 6:20 PM on September 5, 2014: contributor

    @laanwj Thank you It will take me some time to set it up. Don't you have vmWare image I could just grab?

  20. theuni commented at 6:28 PM on September 5, 2014: member

    @ENikS I'm afraid you're on your own for that. We use mingw precisely because it's free to acquire and easy to automate. You won't be able to achieve the same thing with MSVC+Windows because you can't simply spin up an environment without licensing. You'll have to either accept that and cope as well as possible, or get creative as @laanwj suggested with something like Wine+Linux.

  21. ENikS commented at 6:32 PM on September 5, 2014: contributor

    @theuni I see. Let me think about it tonight, can't do much at the office... I will start new issue when I have more questions so discussion can continue there and leave this thread for the warning fix

  22. theuni commented at 6:38 PM on September 5, 2014: member

    @ENikS fwiw, I think a much more realistic next step would be to get a mingw environment up and running under Windows. That I could help with much more, as I'd like to see it happen. We already have a system for building dependencies on/for various platforms (it already builds for windows), it would need to be adapted for use on Windows. You could then use them to build bitcoin with mingw, or coerce it into building with msvc.

  23. ENikS commented at 6:45 PM on September 5, 2014: contributor

    Moved discussion there: #4858

  24. ENikS commented at 2:08 AM on September 11, 2014: contributor

    I think a much more realistic next step would be to get a mingw environment up and running under Windows. That I could help with much more, as I'd like to see it happen. @theuni I am not sure if this is what you wanted to see but it looks like there is no easy way to get these generated files so I setup MinGW on Windows 7 and did the build. It builds the BitcoinD with no issues except it requires a fix for boost 1.56 bug which is described in workarounds directory. I didn't bother with QT but I am sure it could be done as well. https://github.com/ENikS/bitcoin-dev-mingw

  25. BitcoinPullTester commented at 5:25 PM on September 12, 2014: none

    Automatic sanity-testing: FAILED BUILD/TEST, see http://jenkins.bluematt.me/pull-tester/p4824_e283a31376a68e95dc5fbe88b114cacb09d46ffd/ for binaries and test log.

    This could happen for one of several reasons:

    1. It chanages paths in makefile.linux-mingw or otherwise changes build scripts in a way that made them incompatible with the automated testing scripts (please tweak those patches in qa/pull-tester)
    2. It adds/modifies tests which test network rules (thanks for doing that), which conflicts with a patch applied at test time
    3. It does not build on either Linux i386 or Win32 (via MinGW cross compile)
    4. The test suite fails on either Linux i386 or Win32
    5. The block test-cases failed (lookup the first bNN identifier which failed in https://github.com/TheBlueMatt/test-scripts/blob/master/FullBlockTestGenerator.java)

    If you believe this to be in error, please ping BlueMatt on freenode or TheBlueMatt here.

    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.

  26. sipa commented at 5:33 PM on September 12, 2014: member

    Seems pulltester's gcc genuinely can't deal with this code. I believe we'll drop the requirement of the ancient environment it runs on at some point in the future, but as long as it's there, we can't just break it.

  27. theuni commented at 5:42 PM on September 12, 2014: member

    Isn't this a c++11 feature anyway?

  28. ENikS commented at 6:52 PM on September 12, 2014: contributor

    Yes, it is C++11. As far as I knew just about every compiler implements it, even these who do not support full C++11 spec (msvc for example). I guess only actively maintained do. It could be cast to unsigned during the comparison to eliminate the warning but it would be less elegant solution IMHO. Up to you...

  29. sipa commented at 2:40 AM on September 16, 2014: member

    Pulltester uses GCC 4.4 iirc, so it's missing many c++11 features. We'll likely drop pulltester soon, though.

  30. ENikS commented at 5:07 AM on September 16, 2014: contributor

    I guess it can wait

  31. laanwj commented at 8:49 AM on September 25, 2014: member

    Another one waiting for #4907.

  32. laanwj commented at 6:57 AM on October 2, 2014: member

    Needs rebase; this structure is now in src/chain.h. Apart from that it can be merged now.

  33. Fixing C4018 warning d596ede047
  34. ENikS commented at 5:34 PM on October 6, 2014: contributor

    @laanwj It still fails on one of the platforms.

  35. laanwj commented at 5:38 PM on October 6, 2014: member

    Looks like clang, which is used on macosx, has difficulties with this.

  36. laanwj commented at 3:26 PM on October 31, 2014: member

    Closing this for now. Can be reopened when the consensus on using (subsets of) c++11 changes.

  37. laanwj closed this on Oct 31, 2014

  38. DrahtBot 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