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.

--relaxed_ansi option alignment

Hello,
There is a structure aligned by pragma pack(1). I hope non alignment accessing. I copy from structure member to local variable. it instruction is used by LDNW. But when I add relaxed_ansi compiler option, it instruction is used by LDW. Could you tell me the cause?
Best regards

- DSP: C66xx
- CCS: v5.1.1
- CGT: v7.4.2

-mv6600 --abi=eabi -g --include_path="C:/Program Files/Texas Instruments/C6000 Code Generation Tools 7.4.2/include" --relaxed_ansi --display_error_number --diag_warning=225 --diag_wrap=off

-------
#pragma pack(1)

typedef union ul_ipadrs_ipv4
{
 char   ucd[1];
 unsigned long uldt;
 char   ucdt[4];
} UL_LPIPADRS_IPV4;

UL_LPIPADRS_IPV4 *up_ipadrs;
UL_LPIPADRS_IPV4 up_ip;

main()
{
 up_ipadrs = &up_ip;
 unsigned long ul = up_ipadrs->uldt;
}

  • I don't know.  The packed pragma should not be affected by relaxed ANSI mode.  I've submitted SDSCM00047215 for further analysis.

  • There are 2 problems in your question:

    1) You can not use #pragma pack(n) on union. it can only be used on class/struct. In union, every member shares the same location and it is aligned to the biggest member. I guess you have a type there.

    2) #pragma pack(n) can only be used under --gcc option. On C6000 family processor, it is only supported on C6600, C6740, c64+ and c64. So it depends on which subtarget you use.

    You can try the following compilation options to compile your code, it should work. If not, please let me know and I will look further.

    cl6x --gcc -mv6600 test.c

    hope this helps,

    wei

  • Hello,

    Thank you for your information.

    1) I tried to change the definition from "union" to "struct". It works. Is it a limitation of #pragma pack(n)?
    typedef union ul_ipadrs_ipv4
    //typedef struct ul_ipadrs_ipv4

    2) I tried to add -gcc compiler option. It doesn't work.
    -mv6600 --abi=eabi -g --include_path="C:/Program Files/Texas Instruments/C6000 Code Generation Tools 7.4.2/include" --relaxed_ansi --gcc --display_error_number --diag_warning=225 --diag_wrap=off

    Regards

  • 1) #pragma pack(n) is a feature introduced in GCC compiler. We just try to match that. For detailed description of this pragma, you need to read the GCC web site.

    2) You should use the following option:

    -mv6600 --abi=eabi -g --include_path="C:/Program Files/Texas Instruments/C6000 Code Generation Tools 7.4.2/include" --gcc --display_error_number --diag_warning=225 --diag_wrap=off

    Remove the --relaxed_ansi option,

    If there is still a problem, please send us the .asm file and tell us where you think the problem is.

    Thanks.

    Wei

  • Hello,

    Thank you for your reply. My customer said this case is no problem. Because even though the instruction is not  LDNW,  the union member is aligned by 4byte.

    Regards

  • Great.

    union has different alignment rule than the member of a struct. the #pragma pack(n) does not apply to union.

    So I will close CQ47215.

    Any more problem, let us know.

    Wei