...pack C structures [ARM]?

Comments

5 comments

  • Avatar
    John Russell

    I tried the __attribute__ ((packed)) method and got compile errors like

    found '(', expecting ';'

    and ! missing prototype

    when using the MSP430 version, so am I missing an include or similar?

    #pragma pack(1) ............... #pragma pack() is a commonly used pack definition method (Visual C, IAR)

     

    0
    Comment actions Permalink
  • Avatar
    John Russell

    Btw, I'm using the Windows 30 day evaluation version with the pack problem.

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    I've updated the title to show this is for ARM only.

    0
    Comment actions Permalink
  • Avatar
    Andy Heilveil

    the packed attribute has to be applied to data allocations, you can't apply it to a typedef.

    IE you have to remember to apply it to all instances of a type if you want them to be byte-identical.

    typedef struct {
    a_t a;
    b_t b;
    } c_t;
    c_t anInstanceOfC __attribute__ ((packed));

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    ...you apply the packed attribute to a structure (or enumeration).  I use it for a number of things, e.g.

    typedef struct
    {
      unsigned short tcpSrcPort; // network bo
      unsigned short tcpDstPort; // network bo
      unsigned long tcpSeqNo; // SEND data pointer, network bo
      unsigned long tcpAckNo; // Next expected RECEIVE data pointer, network bo
      unsigned char tcpDataOfst;
      unsigned char tcpFlags;
      unsigned short tcpWindow; // how much data we will accept, network bo
      unsigned short tcpChecksum;
      unsigned short tcpUrgent;
      unsigned char tcpOptions[4];
    } __attribute__((packed)) tcpHeader;
    0
    Comment actions Permalink

Please sign in to leave a comment.