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.

CCS/CC1352R: extern variable declaration

Part Number: CC1352R


Tool/software: Code Composer Studio

Hi,

I use CCS9.3 compiler version TI v18.12.5 LTS.

The problem is with declaring union variable like external.

If it is not declared like external there is no errors up to level of optimization level 3 (which is normal)

I have defined global union variable "AA_bb"  in aaa.c file and declared the variable like external "extern" in aaa.h file.

aaa.h file is included in other xxx.c files.

When in release configuration use the level optimization --opt level 3, I receive error "#148 the declaration is incompatiblewith union ...."

Best regards,

Ilian

  • For the source file being built when this happens ...

    Ilian Chakarov said:
    When in release configuration use the level optimization --opt level 3, I receive error "#148 the declaration is incompatiblewith union ...."

    ... please follow the directions in the article How to Submit a Compiler Test Case.

    Thanks and regards,

    -George

  • Hi Gorge,

    attached here is the .pp file.

    LF.pp.txt

    C:/ti/ccs910/ccs/tools/compiler/ti-cgt-arm_18.12.5.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me -O2 --opt_for_speed=3 --include_path="C:/ti/simplelink_sdk_wifi_plugin_2_40_00_22/source/third_party/mbedtls/include/" --include_path="C:/ti/simplelink_cc13x2_26x2_sdk_4_10_00_78/source/ti/devices/cc13x2_cc26x2/driverlib" --include_path="C:/ti/simplelink_cc13x2_26x2_sdk_4_10_00_78/source/ti/drivers/dpl" --include_path="C:/ti/simplelink_cc13x2_26x2_sdk_4_10_00_78/source/ti/posix/ccs" --include_path="C:/ti/simplelink_sdk_wifi_plugin_2_40_00_22/source" --include_path

    Best regards,

    Ilian

  • Thank you for the test case. I can reproduce the problem.  I always see this error diagnostic without regard to the optimization level ...

    line 35328: error: declaration is incompatible with "union <unnamed> LF_Flags" (declared at line 19127)

    Near line 35328 there is this code ...

    union
    {
      unsigned char LF_Flags1;
      struct
      {
        unsigned char Flag1:1;              // Future usage.
        unsigned char Flag2:1;              // Future usage.
        unsigned char LF_Reception:1;       // Will be set when the reception is enabled.
        unsigned char LF_Receiving:1;       // Will be set when the reception is in progress.
        unsigned char LF_ReceivedMsg:1;     // Will be set when there is a received valid message.
        unsigned char LF_RepeatReception:1; // Will be set when the reception has to be repeated.
        unsigned char Flag3:1;              // Future usage.
        unsigned char LF_UpdateRegisters:1;
      } LF_Flags1_bit;
    }LF_Flags;
    

    These lines appear to come from the header file PowerCC26XX.h.  

    Near line 19127 there is this code ...

    extern union
    {
      unsigned char LF_Flags1;
      struct
      {
        unsigned char Flag1:1;              // Future usage.
        unsigned char Flag2:1;              // Future usage.
        unsigned char LF_Reception:1;       // Will be set when the reception is enabled.
        unsigned char LF_Receiving:1;       // Will be set when the reception is in progress.
        unsigned char LF_ReceivedMsg:1;     // Will be set when there is a received valid message.
        unsigned char LF_RepeatReception:1; // Will be set when the reception has to be repeated.
        unsigned char Flag3:1;              // Future usage.
        unsigned char LF_UpdateRegisters:1;
      } LF_Flags1_bit;
    }LF_Flags;
    

    These lines appear to come from the header file CC1352R1_LAUNCHXL.h.  

    This is not legal C code.  These lines define a union.  Such a definition can appear only once in a source file.

    It is true that one definition uses extern and the other does not.  The keyword extern makes no difference in this case.  That applies to the declaration of functions and variables, and not a type like this union.

    You need to change the code (or maybe some -D switches?) so these lines appear one time.

    Thanks and regards,

    -George

  • Hi Thanks,

    you are right, this error is for all optimization levels.

    when this union is defined only ones (in  .h file) without "extern", than everything work up to optimization level 3.

    When opt. level is 3  the error is - error #10056: symbol "LF_Flags" redefined: first defined in "./LF.obj"; redefined in "./ManDown.obj"

    Best regards,

    Ilian

  • I apologize.  I overlooked one detail in my previous post.  It explains this ...

    Ilian Chakarov said:
    When opt. level is 3  the error is - error #10056: symbol "LF_Flags" redefined: first defined in "./LF.obj"; redefined in "./ManDown.obj"

    Just for now, presume a header file has this line in it ...

    int LF_Flags;

    Further, presume this header file is included in multiple C files.  Notice this is not a declaration of LF_Flags.  It is more than that.  It is a definition of LF_Flags.  For more on the difference between the two, please see this FAQ (not from TI).  While a program can have multiple declarations of a the same variable, there can only be one definition.

    If you do have multiple definitions of LF_Flags, your program will still build clean when optimization is below --opt_level=3.  Why?  Because the TI ARM compiler implements those multiple definitions with what is called the common model.  Under that model, multiple definitions of the same variable are combined into one.  When --opt_level=3 or higher is used, the compiler may change how the definition of LF_Flags is implemented.  The details are a bit long, so I'll skip them for now.  The important point is that this optimized implementation can only occur once in the program.  Otherwise, you get a diagnostic from the linker similar to ...

    Ilian Chakarov said:
    error #10056: symbol "LF_Flags" redefined: first defined in "./LF.obj"; redefined in "./ManDown.obj"

    In my previous post I focused on explaining why you can only have one definition of that union type.  I overlooked that, in addition to multiple definitions of that type, you also have multiple definitions of the variable LF_Flags.  I apologize for that error.

    Thanks and regards,

    -George

  • Hi George,

    Thanks for the explanation!

    I understand difference between declaration and definition, the problem from previous post exist, when I define that union in ....c file and declare it in .....h file.

    I general is it possible to use union which elements are  accessible from different ..... .c files with optimization level 3?

    Best regards,

    Ilian

  • Ilian Chakarov said:
    I general is it possible to use union which elements are  accessible from different ..... .c files with optimization level 3?

    I'm not sure I understand the question.  I need to see an example of code which does this.  That said, if it is legal C code, then it will work the same regardless of the level of optimization.

    Thanks and regards,

    -George

  • Hi,

    In  .c file:

    union
    {
      unsigned char LF_Flags1;
      struct
      {
        unsigned char Flag1:1;              
        unsigned char Flag2:1;             
        unsigned char Flag3:1;       
        unsigned char Flag4:1;       
        unsigned char Flag5:1;     
        unsigned char Flag6:1;              
        unsigned char Flag7:1;
        unsigned char Flag8:1;
      } LF_Flags1_bit; 
    }LF_Flags;

    In .h file:

    extern union
    {
      unsigned char LF_Flags1;
      struct
      {
        unsigned char Flag1:1;              
        unsigned char Flag2:1;             
        unsigned char Flag3:1;       
        unsigned char Flag4:1;       
        unsigned char Flag5:1;     
        unsigned char Flag6:1;              
        unsigned char Flag7:1;
        unsigned char Flag8:1;
      } LF_Flags1_bit; 
    }LF_Flags;

       

    Best regards,

    Ilian

  • You code combines things that it is better to separate.  Try it this way ...

    In a header file named union_type_header.h ...

    union union_tag_name
    {
      unsigned char LF_Flags1;
      struct
      {
        unsigned char Flag1:1;              
        unsigned char Flag2:1;             
        unsigned char Flag3:1;       
        unsigned char Flag4:1;       
        unsigned char Flag5:1;     
        unsigned char Flag6:1;              
        unsigned char Flag7:1;
        unsigned char Flag8:1;
      } LF_Flags1_bit; 
    };
    
    extern union union_tag_name LF_Flags;

    In only one .c file ...

    #include <union_type_header.h>
    union union_tag_name LF_Flags;

    Thanks and regards,

    -George