Menu

Possible false positive on macro expansion

Daniel R
2023-05-09
2023-05-09
  • Daniel R

    Daniel R - 2023-05-09

    Hi,

    With the following code:

    #include <stdio.h>
    
    #define bar(x) x % 2
    #define foo(x) printf(#x "\n")
    
    int main(void)
    {
        foo(bar(3));
        return 0;
    }
    

    cppcheck returns the following error:

    Checking test.c ...
    test.c:8:5: error: printf format string requires 1 parameter but only 0 are given. [wrongPrintfScanfArgNum]
        foo(bar(3));
        ^
    

    But upon execution I get the expected behaviour:

    $ gcc test.c -o test && ./test
    bar(3)
    

    Can you please confirm it's a false positive?

    Thanks!

     
  • Daniel Marjamäki

    Thanks! It's a preprocessor bug. I have created this issue:
    https://github.com/danmar/simplecpp/issues/296

     
    ❤️
    1

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.