This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

_Bool and pc_lint

trying to use pc-lint with MISRA 2012 I have tried to change in stdbool

    #define bool _Bool
//typedef _Bool bool;


makes no difference

any suggestions?

I get the below type of 'report' all over the place.

bool bIsFahrenheit = false;
^
..\Src\statemachine.c(34,0): Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]

                   ^
..\Src\statemachine.c(34,0): Note 9075: external symbol 'bIsFahrenheit' defined without a prior declaration [MISRA 2012 Rule 8.4, required]

#... ve -e921 */(_Bool) 0/*lint -restore */
                     ^
..\Src\statemachine.c(34,0): Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]


  • One way is to define a typdef for bool and use that instead. MISRA should be happy with it.

    #include <stdbool.h>
    typedef bool bool_t;
    #define FALSE                   ((bool_t)0)
    #define TRUE                    ((bool_t)1)
    
    bool_t bIsFahrenheit = FALSE;
    

  •     #define bool _Bool
    //typedef _Bool bool;
    typedef bool bool_t;
    


    was that what you ment?
    if so, it makes it worse

    ..\Src\statemachine.c(69,0): Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]
    
    bool_t align_mode = false;
                      ^
    ..\Src\statemachine.c(70,0): Note 9075: external symbol 'align_mode' defined without a prior declaration [MISRA 2012 Rule 8.4, required]
    
    #... e -e921 */(_Bool) 0/*lint -restore */
                        ^
    ..\Src\statemachine.c(70,0): Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]
    
            if (align_mode == false)
    #... t -save -e921 */(_Bool) 0/*lint -restore */
                              ^
    ..\Src\statemachine.c(84,0): Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]
    
            if (align_mode == false)
                              ^
    ..\Src\statemachine.c(84,0): Info 731: Boolean argument to equal/not equal
    
    
    

  • Hello Erik,

    Have you used this tool to play around with your code:

    gimpel-online.com/.../genPage.py

    When you put your code in there, it links the error message pages:
    gimpel-online.com/MsgRef.html In that entry it says:
    "You may enable this message and then suppress the message for individual types to obtain special effects. For example the following will enable the message for all but bool." +e970 -esym(970,bool)

    =====

    As for the "MISRA 2012 Directive 4.6, advisory" line in the error message, there is a good discussion here:

    stackoverflow.com/.../does-misra-c-2012-say-not-to-use-bool

    In that page they say: "Directive 4.6 says "typedefs that indicate size and signedness should be used in place of the basic numerical types"."

    Also in that page, one of the posters disagrees with Gimpel's interpretation of Directive 4.6. You might want to check with Gimpel on their forum about this.

  • Vaguely relevant links to promote cross-linky-ness

    Modifications that may be needed to the default lint config file. You might have to make your own tweaks as well:

    www.keil.com/.../misraCompliance5.html

    www.keil.com/.../coreMISRA_Exceptions_pg.html

    You can set the ARM Compiler 6 to emit "MISRA compatible" warnings. See:

    http://www.keil.com/support/man/docs/uv4/uv4_dg_armclang_cmp.htm

    Discussions at

    http://www.keil.com/forum/24035/

    http://www.keil.com/forum/63388/

  • The change you applied really has to make a difference. If it didn't, the most likely reason is that the line you edited was not actually the one where bool was defined, in that run of the compiler. You'll have to watch out for other copies of <stdbool.h> lying around in the configured #include path seen by PC-lint, or other headers that believe they should be doing their own definitions. Note that PC-lint has some fall-back definitions of standard library elements of its own. This message fragment in particular

    #... ve -e921 */(_Bool) 0/*lint -restore */
    

    suggests to me that you're currently finding PC-lint's definition of "false" (from au-misra3.lnt).

  • You'll have to watch out for other copies of <stdbool.h> lying around in the configured #include path seen by PC-lint,

    there are no stdbool in the project directory
    these are the ones in the keil directory

    C:\keil_v5\ARM\ARMCC\include
    C:\keil_v5\ARM\ARMCLANG\include
    C:\keil_v5\ARM\ARMCLANG\include\libcxx
    C:\keil_v5\ARM\ARMCLANG\lib\clang\5.0.0\include

    this is the includes in the project options
    ../Inc;../Drivers/STM32F0xx_HAL_Driver/Inc;../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F0xx/Include;../Drivers/CMSIS/Include;../Touch-user;../Middleware-touch/inc;../Lcd;..\Images

    it seems the Keil directory links are automsatic
    2) if yes, how do I modify w/o getting compile errors

    computer control string from project options:
    --c99 -c --cpu Cortex-M0 -D__MICROLIB -g -O0 --apcs=interwork --split_sections -I ../Inc -I ../Drivers/STM32F0xx_HAL_Driver/Inc -I ../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I ../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I ../Drivers/CMSIS/Include -I ../Touch-user -I ../Middleware-touch/inc -I ../Lcd -I ../Images
    -I./RTE/_GP_TMO
    -IC:/Keil_v5/ARM/PACK/ARM/CMSIS/5.0.1/CMSIS/Include
    -IC:/Keil_v5/ARM/PACK/Keil/STM32F0xx_DFP/1.5.0/Device/Include
    -D__UVISION_VERSION="524" -D_RTE_ -DSTM32F091xC -DUSE_HAL_DRIVER -DSTM32F091xC -DTMO
    -o .\Obj\*.o --omf_browse .\Obj\*.crf --depend .\Obj\*.d

    erik

  • it seems the Keil directory links are automsatic

    For the Keil compiler itself: evidently. For PC-Lint: not so much. Unless the IDE adds its own -i"$(KEILDIR)/ARM..." flags to the PC-lint call automatically, you'll have to do that yourself, in the configuration of the lint integration.

  • typedef unsigned int uint32_t; (stdint) no lint problem
    typedef _Bool bool; (stdbool modified) lint problem.

    the lint issue must be in a difference of what is assigned by the compiler

  • Hello Erik,

    Hello, are you using MDK-ARM version 5.24?
    Are you using ARM Compiler 6 to compiler? Or ARM Compiler 5?

    If so, did you run your code using our C:\Keil_v5\UV4\Lint\Config\MISRA_C_2012_Config.lnt file?
    -This file has some additional MISRA 2012 settings.

    You can follow these steps to setup PC-Lint for MISRA C 2012 support:

    http://www.keil.com/support/man/docs/uv4/uv4_ut_pclint_config.htm

    If you are running MDK-ARM 5.23, the Misra_C files were in the wrong place. See:

    http://www.keil.com/support/docs/3905.htm

  • Hello Erik,

    I looked in the "MISRA C:2012 Technical Corrigendum 1 Technical clarification of MISRA C:2012 June 2017" guide at:

    www.misra.org.uk/LinkClick.aspx

    On Page 7, regarding Directive 4.6, they are using examples of not using plain char instead of signed or unsigned char.

    So if you want to it may be OK to use +e970 -esym(970,bool) in your code to have Lint ignore booleans.

    ... but I am not a language lawyer, so I say ask on: Ask on https://www.misra.org.uk/forum to be safe

    Or on Gimpbel's forum. Not quite the same issue you had, but here was a customer using the C++ MISRA standard, and running into issues with C types and MISRA warnings:

    www.gimpel.com/Discussion.cfm

  • oops instead of "in your code" I should have said use

      +e970 -esym(970,bool)
    

    in your copy of the MISRA-2012 lint configuration file MISRA_C_2012_Config.lnt

  • I'm off this week, will be back next

  • Hello, are you using MDK-ARM version 5.24?
    5.24.1
    Are you using ARM Compiler 6 to compiler? Or ARM Compiler 5?
    ??? Armcc 5.06 build 528

    If so, did you run your code using our C:\Keil_v5\UV4\Lint\Config\MISRA_C_2012_Config.lnt file?
    -This file has some additional MISRA 2012 settings.

    will have a look

    You can follow these steps to setup PC-Lint for MISRA C 2012 support:
    I do not want to suppress a lint warning that may, in some cases, be valid

    Erik