- Apr 10, 2006
- 12,028
- 2
- 0
I've got a structure like this:
struct
{
unsigned char a;
float b;
float c;
}value;
In memory, it puts an extra byte after my unsigned char, which messes up my data when I'm passing the structure as a pointer. I need to have it order, because I'm passing it to some other hardware via serial port. Extra padding at the end doesn't work either.
At this point the only option I can see is to add the padding to the front. The down side to this is that when I'm adding data to the structure (via serial or file i/o), I'll have to skip the first one. And I'll have to exclude it when I'm passing the data back to the serial port. It's not horrible, I was just hoping there would be a more elegant solution to cut down on the complexity.
Suggestions?
struct
{
unsigned char a;
float b;
float c;
}value;
In memory, it puts an extra byte after my unsigned char, which messes up my data when I'm passing the structure as a pointer. I need to have it order, because I'm passing it to some other hardware via serial port. Extra padding at the end doesn't work either.
At this point the only option I can see is to add the padding to the front. The down side to this is that when I'm adding data to the structure (via serial or file i/o), I'll have to skip the first one. And I'll have to exclude it when I'm passing the data back to the serial port. It's not horrible, I was just hoping there would be a more elegant solution to cut down on the complexity.
Suggestions?