This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TI ARM compiler v5.2.0 no longer defines __GNUC__ when --gcc is used

When the -gcc option was used to enable support for GCC extensions the TI ARM compiler v5.1.9 defined the symbol __GNUC__

However, with TI ARM compiler v5.2.0 using -gcc no longer causes the compiler to define the symbol __GNUC__

Was this change intentional?

[I noticed it when got compile errors trying to use TI ARM compiler v5.2.0 to compile the ARM CMSIS-SP-00300-r4p2-00rel0, since some of the CMSIS source code checks for  __GNUC__ being defined when checking if the compiler is known]

  • Chester Gillon said:
    Was this change intentional?

    Yes.  The predefined name __GNUC__ is never mentioned in the documentation.  However, I did discuss it in a forum post.  I will go back to that thread and add a post to correct my error.

    The behavior of the compiler with regard to whether GCC extensions are available has changed from version to version.  The details are in this wiki article.

    As a workaround, you could develop your own preprocessor symbol to indicate whether GCC extensions are available.  Here is a starting point ...

    #if __TI_COMPILER_VERSION__ >= 5002000    /* 5.2.0 or higher */
    
       #if !__TI_STRICT_ANSI_MODE__
       #define MY_GNUC 1
       #else
       #define MY_GNUC 0
       #warn "GNU extensions not available"
       #endif
    
    #elif __TI_COMPILER_VERSION__ >= 5000000   /* 5.0.0 or higher */
    #define MY_GNUC __GNUC__
    
    #else
    #warn "GNU extensions may not be available"
    
    #endif
    

    In version 5.2.x, you can key on whether --strict_ansi is being used.  If it is not being used, then GCC extensions are available.  In versions 5.1.x and 5.0.x, you can rely on the compiler defined preprocessor symbol __GNUC__.  For older versions, there is no compiler defined preprocessor symbol like __GNUC__.

    Thanks and regards,

    -George