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.

Pragma PACK issue

Part number - CC3000 (ARM M core)

I looked over several Pragma Pack forum posts, but couldn't find a smoking gun...  I suspect an obscure compiler  switch somewhere...  Question from customer: 

I’m trying to define a packed structure within my code.  Currently I am using the Strict ANSI mode to compile and I would like to keep it that way.  If you check the GCC extension and disable Strict ANSI, you can pack a struct as follows:

struct __attribute__ ((__packed__)) struct_name {uint8_t data0; uint8_t data1;};

 If you still want to use Strict ANSI, you should be able to use the pragma PACK as follows:

#pragma PACK (1)

struct struct_name {uint8_t data0; uint8_t data1;}; 

However, when I compile my project, it says “#163-D unrecognized #pragma”.  The Help on CCS shows the pack pragma should be recognized.  After searching, it seems the PACK pragma was first supported by IAR.  I’ve seen some much older posts that says it was supposed to be available for CCS as well in the future.  Any ideas?

  • What version of the TI ARM compiler are you using?  (It is not the same as the CCS version.)

  • The customer writes:

    The compiler version is TI v4.3.2. I changed it to v4.3.3 (the latest I have installed) and still get the same issue.

  • I'm sorry, I can't find an ARM or TMS470 compiler version 4.3.2 in our release list.  Are you sure that's the right compiler version?  You might find the compiler version number in the build console.  Also try running cl470 --tool_version

    [ Edit: cl470, not cl430.  If it turns out your compiler is actually 5.0.0 or later, it's armcl instead -- Archaeologist ]

  • Just a thought: try lower case.  I was getting unrecognized pragma with DIAG_SUPPRESS and DIAG_DEFAULT until I thought to try lower case.

  • Hi Walter.  The lowercase seemed to work, however when tested, it seems the pack pragma doesn't quite do the same thing as __attribute__ ((__packed__)).  I'm not entirely sure what's going on, but if I use the pack pragma, I get a linker error that says a different struct than the ones I am using the pack pragma on is being redeclared with incompatible type.  I have attached the two files that have the structs.  Currently I have whole program optimizations (4) turned on along with it being optimized for speed at 5.  If I turn the optimizations to 3, then the error goes away, but I still think the structs aren't being accessed properly as when I read the data it seems to be erroneous.

    Description         Resource             Path       Location               Type

    #10192 Failed linktime optimization         Test_Compiler                                 C/C++ Problem

    Description         Resource             Path       Location               Type

    symbol "gt_product_property_values" redeclared with incompatible type:         Test_Compiler                                 C/C++ Problem

    I can post source if that helps.

    Thanks!

  • Please attach the full contents of the Console view (not the Problems view) which shows those diagnostics.  Please attach the source files referred to, preprocessed like this.  

    Thanks and regards,

    -George

  • Thank you for submitting a test case through other channels.  I can reproduce your results.  I filed SDSCM00050642 in the SDOWP system to have this investigated.  Feel free to follow it with the SDOWP link below in my signature.

    This appears to be a bug related to your use of --opt_level=4 (or -O4 for short).  It builds clean with --opt_level=3.  Please see if that workaround is practical.

    Thanks and regards,

    -George

  • The problem is that you are using the non-push/pop form of pack.  This form of pack affects ALL subsequent struct definitions in the file, which is not what you want.  Wrap each struct you want to be packed with the following pair.

    #pragma pack(push, 1)
    #pragma pack(pop)

    The MSP430 compiler manual is incorrect about the behavior of "#pragma pack(n)."  I'll submit a defect report for that.