Menu

manage #pragma inside code

michele
2015-10-29
2015-11-09
  • michele

    michele - 2015-10-29

    Hello,
    I'm using cppcheck in a Iar project where we use sometimes the #pragma and cppcheck (we run 1.67) seems to not correctly manage them. I saw that problem was already rised sometime ago but I don't understand how it was solved.
    thanks
    Michele

     
  • michele

    michele - 2015-11-02

    hello,
    is there no solution to this problem? My other option is to pre-process the files and remove the pragma ..
    Thanks for the support
    Michele

     
  • Daniel Marjamäki

    can you describe the problem further? a small example code with a #pragma that reproduce the problem would be very nice.

     
  • michele

    michele - 2015-11-04

    Hello,
    Thanks a lot for the support.
    here it is an example

    void reset( void )
    {
    U16 zIndex;
    U16* pzDebug;

    pzDebug = &MyDebug.debug0;

    for ( zIndex = 0U; zIndex < 15; zIndex++ )
    {
    MISRAC_DISABLE
    pzDebug[zIndex] = (U16)0;
    MISRAC_ENABLE
    }
    }

    and the output of cppcheck

    warning: cppchecker:style,unreadVariable,Variable 'pzDebug' is assigned a value that is never used."

    The 2 defines are defined in the current way (I'm sorry but I don't know why the font is so big!):

    /
    * IAR MisraC checker Enable/Disable
    */

    define MISRAC_DISABLE _Pragma ("diag_suppress=Pm001,Pm002,Pm003")

    define MISRAC_ENABLE _Pragma ("diag_default=Pm001,Pm002,Pm003")

     
  • Daniel Marjamäki

    ok.

    Cppcheck will not handle this internally. You need to configure it somehow.

    There are many choices for how to configure this.

    1: You can write and use an iar.cfg file that explains iar extensions.

    Here is an example iar.cfg

    <?xml version="1.0"?>
    <def format="1">
      <define name="_Pragma(X)" value=""/>
      <define name="MISRAC_DISABLE" value=""/>
      <define name="MISRAC_ENABLE" value=""/>
    </def>
    

    You can use it with a "--library=iar" like this:

    $ cppcheck --library=iar test1.c
    

    2: You can write an extra header for Cppcheck where IAR macros are defined

    iar.h:

    #define MISRAC_ENABLE
    #define MISRAC_DISABLE
    #define _Pragma(X)
    

    Then use "--include=iar.h" like this:

    $ cppcheck --include=iar.h test1.c
    

    3: You could use -D and -U at the command line also. How you do that depends on how the iar macros are defined, what -I you use, and if you want to check more than 1 ifdef configuration.

     

    Last edit: Daniel Marjamäki 2015-11-06
  • michele

    michele - 2015-11-07

    Hello,
    thanks a lot for the support. I did a fast try with my batch but it was not working but I didn't have time to investigate. I will test better on monday. Thanks again and have a nice weekend

     
  • michele

    michele - 2015-11-09

    Hello,
    today I tested it and it works perfectly.
    thank you very much for the support.
    Michele

     

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.