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.

data packing on 6455 dsp



Hi all,

My question is as follows:

 

Say you have the following classes:

class BaseClass{

public:

   int basevar;

};

 

class ChildClass : public BaseClass{

public:

 int childVar1;

 int childVar2;

};

 

I am using a CGT 6.1.11, and what I see happening is the BaseClass is being padded with 4 bytes so that it is eight-byte aligned, and thus sizeof(ChildClass) is 16 rather than 12.  My problem stems from the fact that I am transmitting various objects like this out via the MCBSP and reading them in on another embedded device.  When I try to parse the incoming data stream, I get the wrong result because the other embedded device (with code compiled via gcc) does not pad structures so that, on the other embedded device, sizeof(ChildClass) would be 12.  Is there some way to gracefully handle this?

 

Many thanks,

-B

  • Using structures to exchange data between devices is not a good idea.  Structure layout is not strictly specified in the standard.  Compilers for the same device may do it differently.  Compilers for different devices almost certainly do it differently.  A good discussion on this topic is here http://c-faq.com/struct/io.html .

    Thanks and regards,

    -George

     

  • As I understand it, using packed data structures would likely solve this problem.  However, the packed data structure gcc extension is not currently supported in the TI compiler tools (2010/01).  The compiler may provide support for packed data structures in the future.  And of course the packed data structure extension is non-standard and different compilers may implement it differently.  Caveat utilitor.

  • Thanks for the responses.  I think I can fix this by specifying an alignment for the non-dsp device (however bad an idea this whole thing may be in general).

    -B.