explicitly use unsigned values in ByteReverse() #3057

pull Diapolo wants to merge 1 commits into bitcoin:master from Diapolo:ByteReverse_unsigned changing 1 files +2 −2
  1. Diapolo commented at 11:18 AM on October 5, 2013: none

    No description provided.

  2. explicitly use unsigned values in ByteReverse() 5bc71a57da
  3. BitcoinPullTester commented at 11:56 AM on October 5, 2013: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/5bc71a57daeaa0af54ff61c2dfbffd1357718e7e 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.

  4. laanwj commented at 6:31 AM on October 10, 2013: member

    As I understand it according to the C standard, this changes nothing.

    http://c0x.coding-guidelines.com/6.3.1.8.html :

    714 Otherwise, if the operand that has unsigned integer type has rank greater or equal to the rank of 
    the type of the other operand, then the operand with signed integer type is converted to the type of 
    the operand with unsigned integer type.
    

    int and unsigned int have the same rank, so the result of the all the operations in this function is unsigned int exactly as we want.

  5. Diapolo commented at 6:35 AM on October 10, 2013: none

    Yeah, even if it doesn't change behaviour, as was intended, it allows at first look what is done there IMO. If this is unneeded, just close the pull :).

  6. laanwj commented at 6:53 AM on October 10, 2013: member

    It is important to specify U explicitly in cases where you're working with types of different rank, for example int and unsigned short. As the rank of the signed type is larger in that case the result will be a signed int, which might be not what you want.

    Whether it makes sense to do it here is a matter of taste / coding style. Usually it's indeed better to be explicit to prevent bugs due to undefined behavior popping up. And for bitwise arithmetic you should use unsigned types.

    But this has its limits in practicality, it's not like it's necessary or more readable to add 'U' behind half the values in the program :)

  7. jgarzik commented at 10:39 AM on October 10, 2013: contributor

    NAK, not needed

  8. jgarzik closed this on Oct 10, 2013

  9. Bushstar referenced this in commit a78dcfdec2 on Apr 8, 2020
  10. 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-21 18:16 UTC

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