Menu

C - Syntax error on typedef enum

2021-03-15
2021-04-29
  • Simon THIEBAUT

    Simon THIEBAUT - 2021-03-15

    Hello,

    I'm facing an issue with a typedef enum in a C project.
    I have the following message in CppCheck output file: "error: syntax error [syntaxError]
    typedef enum{" (the error arrow points to the "e" of enum in this message).
    This errors refers to enum RetStatus_t of the below header file.

    I've tried to:
    - move the enum in another header => error follows the enum
    - move the enum lower in the same file => error follows the enum
    - remove all dependencies to the enum => error still there
    - comment the enum => error disappears.

    I'm really confused, it compiles properly, and I cannot find what could be wrong with the writing of this enum.
    Also, I've read many CppCheck topics in the past with enum issues, but they were linked to CPP project, with enum classes.

    Do you have any ideas ?

    Heare are the details around CppCheck usage (I've kept the make variables):
    - version 2.3
    - command: cppcheck $(C_SOURCES) $(C_DEFS) $(C_INCLUDES) --enable=warning --suppressions-list=./cppcheck/cppcheck_suppression_list.txt --enable=information --output-file=./cppcheck/cppcheck_errors.txt --error-exitcode=31

    Thank you for your help.

    #ifndef __FWK_UTILS_H__
    #define __FWK_UTILS_H__
    
    
    /* Generic return type used by framework */
    typedef enum{
        STATUS_OK       = 0,
        STATUS_ERROR    = 1,
        STATUS_BUSY     = 2,
        STATUS_TIMEOUT  = 3,
        STATUS_CANCELED = 4
    }RetStatus_t;
    
    typedef enum{
        FW_DRV_OK = 0,
        FW_DRV_FAIL,
        FW_DRV_TIMEOUT,
        FW_DRV_INVALID_CONFIG,              /*!< configuration parameters incorrect */
        FW_DRV_MODE_NOT_SUPPORTED,          /*!< controller/driver doesn't support this mode (master/slave) */
        FW_DRV_CONTROLLER_IN_USE,           /*!< controller is in use */
        FW_RC_CONTROLLER_NOT_ACCESSIBLE,    /*!< controller not accessible from this core */
        FW_DRV_INVALID_OPERATION,           /*!< attempt to perform an operation that is invalid */
        FW_DRV_WRITE_PROTECTED,             /*!< Attempt to erase/program a memory region that is write protected */
        FW_DRV_READ_PROTECTED,              /*!< Attempt to read a memory region that is read protected */
        FW_DRV_CHECK_FAIL,                  /*!< Read back data after programming does not match the word written to memory */
        FW_DRV_POINTER_NULL,                /*!< Attempt  to use null pointer */
        FW_DRV_OUT_OF_MEM,                  /*!< Attempt to program data outside the memory boundaries */
        FW_DRV_BUSY,
    }FRAMEWORK_API_RC;
    
    
    #endif /* __FWK_UTILS_H__ */
    
     

    Last edit: Simon THIEBAUT 2021-03-15
  • Daniel Marjamäki

    I can't reproduce with this code. I don't think the problem is this particular code.

    could you try to bisect your code.. try to produce a small code example that demonstrates the problem. I'd first determine which C-file cppcheck checks when this happens.. then see if you can remove various includes,functions, etc.. I'd start commenting out all includes that are not needed because that removes lots of code quickly.

     
    • Simon THIEBAUT

      Simon THIEBAUT - 2021-04-27

      Hi Daniel,

      Thank you for your feedback.
      I've finally got time to investigate further, and it appears that one of the enum value (STATUS_TIMEOUT) conflicts with a define in a file of cppcheck:
      - file cppcheck/cfg/winfows.cfg
      - line "<define name="STATUS_TIMEOUT" value="(0x00000102L)">"</define>

      If I rename the name inside the windows.cfg file, then my error disappears.
      I need to document my self more about this to understand what happens, and to avoid renaming my enum value, but in the meantime if you have an obvious solution, I'll be happy to get it.

      Thank you.

       
  • Simon THIEBAUT

    Simon THIEBAUT - 2021-04-27

    Some new findings !

    Actually I'm cross compiling for an embedded target (STM32, which is ARM CORTEX based).

    If I add the following option: "-platform=unspecified", the conflict disappear.... my guess is that if I don't specify this option, a default value is taken, that uses the windows.cfg file (probably because I'm developing on a Windows computer).

    I'll keep that option, but if anyone could confirm (or not), I would feel more confident.

    Thank you.

     
  • Daniel Marjamäki

    the default --platform setting is native and as you guessed if you use the windows binary it will match win64.

    actually I would recommend that you use some --platform= option that match your platform. doesn't any file here https://github.com/danmar/cppcheck/tree/main/platforms work for you? You can easily create a stm32.xml file. If you do that then feel free to share it so I can add it.

     
  • Simon THIEBAUT

    Simon THIEBAUT - 2021-04-29

    Thank you for this info. Indeed the existing platform=arm32-wchar_t4 fits perfectly for my STM32 context, as it is ARM32 based, along with my default compiler value of wchar_t.

    Many thanks again !

    PS: it's my first discussion ever on SourceForge, I haven't still found how to mark as resolved or even how to edit the title to indicate it, so please feel free to do it if it's feasible.

     

    Last edit: Simon THIEBAUT 2021-04-29

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.