# structure packing

**URL:** <https://forums.digi.com/t/structure-packing/6265>\
**Category:** Linux\
**Created:** [September 24, 2007, 2:17pm UTC](https://forums.digi.com/t/structure-packing/6265 "2007-09-24T14:17:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeDC](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@MikeDC](https://forums.digi.com/u/MikeDC)\
**Post date:** [September 24, 2007, 2:17pm UTC](https://forums.digi.com/t/structure-packing/6265/1 "2007-09-24T14:17:36Z")

</div>

Hi,

I have an application that depends on structure sizes. When I compile with the arm g++ and ucLibc my packets are in size chunks of 4 bytes.

I already tried both of these flags -fpack-struct and -fshort-enums. they work when I compile with g++ for an intel ubuntu linux target application, but when I port to the Arm based ConnectME the structures default to 4 byte sizes. any ideas?

oh. and I also tried **attribute** (( **packed** ))

Message was edited by: MikeDC

---

<div class="post-metadata">

**Author:** ![MikeDC](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@MikeDC](https://forums.digi.com/u/MikeDC)\
**Post date:** [September 26, 2007, 4:52pm UTC](https://forums.digi.com/t/structure-packing/6265/2 "2007-09-26T16:52:06Z")

</div>

I messed around and found that my problem was that my struct was within a union. So using **attribute** (( **packed** )) worked when i moved the struct out of the union.

Just to let you know the union had all 1 byte elements, and to be clear my Ubuntu g++ (gcc ver 4.01) compiled it fine when it was in the union. The arm-g++ was gcc ver 2.95.3

* * *

also here is an email from Leonid from Digi:  
I did some research and discovered that: older versions of G++ had a bug ignoring -fpack-struct:

> **[G++ ignores -fpack-struct: bug?](https://gcc.gnu.org/legacy-ml/gcc-bugs/1999-02n/msg00633.html)**

This might be one of the things you are seeing, also **attribute** (( **packed** )) is known not to work prior to gcc 4.0.0…

Also have you tried something like this:  
#pragma pack(2)  
int x2 **attribute** ((aligned(2)));

## Please also check this discussion, it sounds like they talk about the same problem with some possible workarounds: [http://www.cocoabuilder.com/archive/message/xcode/2005/11/19/1306](http://www.cocoabuilder.com/archive/message/xcode/2005/11/19/1306)
