Menu

Problem with macro expansion

greenfoo
2024-09-30
2024-10-03
  • greenfoo

    greenfoo - 2024-09-30

    The following C program compiles, but cppcheck reports a macro expansion problem:

    #define ADDER_S(a,b) a+b
    #define ADDER(x) ADDER_S(x)
    #define ARGUMENTS 1, 2
    
    #define RUN  ADDER(ARGUMENTS)
    
    int test(void) {
        //ADDER(ARGUMENTS);                     // Works
        RUN;                                    // Fails!!
        return 0;
    }
    

    The actual error looks like this:

    $ cppcheck test.c
    test.c:2:0: error: failed to expand 'RUN', Wrong number of parameters for macro 'ADDER_S'. [preprocessorErrorDirective]
    #define ADDER(x) ADDER_S(x)
    

    I'm testing with the latest commit of master (6d56c7fc0d353b010c4ef2892e8d6a1403e7dd98)

     

    Last edit: greenfoo 2024-10-01
  • CHR

    CHR - 2024-10-01

    Probably should be reported here: https://github.com/danmar/simplecpp/issues

     
  • CHR

    CHR - 2024-10-02
     
  • greenfoo

    greenfoo - 2024-10-03

    Thanks for creating the bug report!

     

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.