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: structure format

Other Parts Discussed in Thread: TEST2

Tool/software: Code Composer Studio

Hi all,

  I set up the following structure:

struct _Test{
    unsigned char Test1;
    unsigned int Test2;
    unsigned long Test3;
};

in memory every item gets a 4 byte RAM spot. one would assume that there will be 7 Bytes allocated, in fact there are 12 bytes allocated???

I use it with the CC2652

Any ideas, how to set the actual Bytes??

t6hanks for your help

best regards

Kurt

  • Hi Kurt,

    It is pretty normal behaviour in C and any other language. It is called data structure alignment.

    If you want to use "packed structure", you need to say compiler that structure should be packed. But you should use "packet structure" only if you really need, because your code will be less more efficient. For example you can use something like that:

    #pragma pack(push, 1)
    
    typedef struct {
     unsigned char Test1;
     unsigned int Test2;
     unsigned long Test3;
    } _test;
    
    #pragma pack(pop)

    Jan

  • Thank you to Jan D for posting that reply.  I can confirm it is correct.  

    Another way to see what happens ... Use the utility global_types_gen from the cg_xml package.  It shows you the layout of all the structures in the program.  For this specific structure, here is the output ...

    _Test                          // Size in MADUs == 12
             unsigned char                 Test1                 // Offset == 0
             unsigned int                  Test2                 // Offset == 4
             unsigned long                 Test3                 // Offset == 8

    Thanks and regards,

    -George