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.

Attribute 'packed' error on compiler v4.4 for C55x

Hello,

I want to use a "packed" attribute for struct  type. The manual (compiler version 4.4) says that it support variaous attributes.

but i faces below error message( gcc option is enabled).

struct __attribute__((__packed__)) test{ char c1; int t;  };

--.> error : invalid atttibute for "struct test"

Another attriutes such asaligned or deprecated don't have any issue. Only "parked" attribute has the error.

How can I slove it?

Thank you.

 

----- dev environment-----

ccs 5.x

compiler v4.4

DSP : C55x

--------------- from compiler version 4.4----------------

5.14.4 T ype Attributes The following type attributes are supported: aligned, deprecated, packed, transparent_union, and unused. Members of a packed structure are stored as closely to each other as possible, omitting additional bytes of padding usually added to preserve word-alignment. For example, assuming a word-size of 4 bytes ordinarily has 3 bytes of padding between members c1 and i, and another 3 bytes of trailing padding after member c2, leading to a total size of 12 bytes: struct unpacked_struct { char c1; int i; char c2;}; However, the members of a packed struct are byte-aligned. Thus the following does not have any bytes of padding between or after members and totals 6 bytes: struct __attribute__((__packed__)) packed_struct { char c1; int i; char c2; }; Subsequently, packed structures in an array are packed together without trailing padding between array elements.

  • According to the following wiki page, C5500 does not support the packed attribute:

    http://processors.wiki.ti.com/index.php/GCC_Extensions_in_TI_Compilers

  • So far as I know there are only two motivations for wanting to used "packed" data structures:

    (1) Minimize data size;

    (2) Conform to some externally-impose record format.

    For point (1), reorder the structure member declarations so larger types come before smaller types.  In general, you can't get rid of padding at the end of each struct without adversely impacting execution speed.

    For point (2), it is better for portability to create and use some "marshalling" functions which pack and unpack various basic data types to and from byte arrays at arbitrary alignments.  Use the native (aligned) types for all computation, and convert to/from packed records at the I/O interface level.

    Good luck!