Menu

Preprocessor produces negative unsigned numbers

vilox
2021-01-21
2021-01-23
  • vilox

    vilox - 2021-01-21

    Let's check this test.c:

    #if ((0x7fffffffffffffffL * 2UL) < 0)
    # error LOL
    #endif
    

    $ cppcheck -DANYTHING --enable=all test.c
    Checking test.c ...
    test.c:2:0: error: #error LOL [preprocessorErrorDirective]
    # error LOL
    ^

    The more fun is that that the left operand may be unsigned and the expression continues to be negative from cppcheck point of view. The expressions below are also considered negative by cppcheck preprocessor:

    (0x7fffffffffffffffUL * 2UL)
    (0x7fffffffffffffffUL << 1UL)
    (0x7000000000000000UL + 0x1000000000000000UL)
    (0x4000000000000000UL << 1UL)
    (1UL << 63UL)
    

    The platform is Debian 10 x64. Verified for cppcheck current release (2.3) and current git (2020-12-28 b94a6d595).

     
  • Daniel Marjamäki

    Thanks! I have created this issue: https://github.com/danmar/simplecpp/issues/207

     

    Last edit: Daniel Marjamäki 2021-01-23

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.