Structure padding Issue in Q2686


#1

Hai all,
am using,

Module :: Q2686G.
The firmware version is :: R74_00gg.Q2686G
Application OS :: 06.21
Boot loader version :: V08b0e

consider the following structure,

typedef struct{
char ch;
}TEST;

if we get the size of this structure means, its showing 4 bytes.
Is there any thing like pragma pack in keil which will remove structure padding and consuming one byte alone in M2M studio?

thank you,


#2

This depends on the compiler - it has nothing specifically to do with M2M Studio.

I presume you’re using the GCC compiler? If so, you need to study the GCC compiler manual - search your M2M Studio installation folder for gcc.pdf.

However, before you do that, it would help if you would explain what, exactly, you are trying to achieve by this?

If people know what you are actually trying to achieve here, they may well be able to suggest better ways to go about it…

Beware that the compiler doesn’t just put this padding in for fun: unaligned accesses can have serious consequences for your application… :open_mouth:


#3

Yes, I am using GCC compiler. I have found that the pragma facility is available.

we are trying to reduce the data bytes, that get transferred in GPRS between peers.

“Beware that the compiler doesn’t just put this padding in for fun: unaligned accesses can have serious consequences for your application… :”

yes totally agreed… thank you awneil…


#4

It rather clogs the forum up when you just block-quote the entire message.
It’s only really useful to quote when you need to make clear which specific point you are referring to; eg,

I would suggest, from experience, that packing your structures is not a good way to do it!
The issues it raises with the rest of your code are just not worth it.

Instead, have your code build the message in a byte buffer (without padding) - and just send that buffer…

This also has the advantage of making your code portable, and not reliant upon particular compiler features & options…


#5

I agree, this is exactly what I do.

I think another method is to use unions eg:

typedef union
{
u8 ch_8;
char ch;
}TEST

Not 100% sure, but I think you could just reference the u8 part and get 8 bit data :slight_smile:


#6

That relies entirely upon compiler-specific implementation details.

It is also likely to be subject to padding/alignment issues.


#7

True.