Menu

Concatenation of unknown macros

Alessandro
2023-08-02
2024-10-08
  • Alessandro

    Alessandro - 2023-08-02

    Hi,
    when I concatenate two unknown macros cppcheck doesn't work anymore and if there are errors in the C file they are not found.
    Example macro:

    #define MAJOR_VER 1
    #define MINOR_VER 2
    #define BFLRLY_VERSION_STRING (UTLGEN_TO_STR(MAJOR_VER)  UTLGEN_TO_STR(MINOR_VER))
    

    Where "UTLGEN_TO_STR" is a unknown macro.
    When call cppcheck i suppress unknownMacro .

    Do you have an idea about a possible solution?

    Best Regards,
    Alessandro

     
  • Alessandro

    Alessandro - 2023-10-03

    Hi,

    do you have any update to fix this problem?

    Best Regards,
    Alessandro

     
  • CHR

    CHR - 2023-10-04

    You can pass -DUTLGEN_TO_STR=... to cppcheck to define a macro. Or maybe make the header that UTLGEN_TO_STR resides in visible to cppcheck?

     
  • Alessandro

    Alessandro - 2023-10-04

    I don't want to use cppcheck on the file where UTLGEN_TO_STR is defined.
    For this reason I suppressed unknownMacro.

    The problem is that the generated dump files where there is this line of code
    #define BFLRLY_VERSION_STRING (UTLGEN_TO_STR(MAJOR_VER) UTLGEN_TO_STR(MINOR_VER))
    are incorrect and cppcheck no longer works.

    Is there an option in cppcheck to avoid having this problem?

    Is there a rule to prevent malformed dumps from being created due to the presence of unknownMacro?

     
  • Alessandro

    Alessandro - 2024-10-02

    Hi,

    Could you please let me know if there are any updates on this ticket?

    Thanks a lot!
    Alessandro

     
  • Daniel Marjamäki

    I would suggest you follow advice by chr. Define UTL_GEN_STR in some way.

    If you don't want to include the header and you don't want to use -D then how about something like:

    #ifdef __cppcheck__
    #define UTLGEN_TO_STR(VER)  #VER
    #endif
    #define MAJOR_VER 1
    #define MINOR_VER 2
    #define BFLRLY_VERSION_STRING (UTLGEN_TO_STR(MAJOR_VER)  UTLGEN_TO_STR(MINOR_VER))
    

    An extra -D__cppcheck__ would still be needed for this.

    If there are unknownMacro warnings then cppcheck must abort there must be code that we cannot parse well. In general unknown macros do not result in unknownMacro warnings and aborted analysis.

     

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.