how to Pack structure ?

bridged with qdn.public.qnxrtp.applications
Post Reply
Yasmine

how to Pack structure ?

Post by Yasmine » Mon Apr 29, 2002 8:47 am

Hi,

I would like to pack a structure

i tried

typedef struct {
char var1
float var2
int var3
}MypackedStruct __attribute__((packed));

but seems to do anything better than without the attribute.

I run QNX6RTP with qcc

Any idea ?

David Gibbs

Re: how to Pack structure ?

Post by David Gibbs » Mon Apr 29, 2002 3:39 pm

Yasmine <y.leroux@nospam.actris.com> wrote:
Hi,

I would like to pack a structure
Take a look at /usr/include/_pack*.h

-David

i tried

typedef struct {
char var1
float var2
int var3
}MypackedStruct __attribute__((packed));

but seems to do anything better than without the attribute.

I run QNX6RTP with qcc

Any idea ?

--
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Colin Burgess

Re: how to Pack structure ?

Post by Colin Burgess » Tue Apr 30, 2002 12:29 am

Yasmine <y.leroux@nospam.actris.com> wrote:
Hi,

I would like to pack a structure

i tried

typedef struct {
char var1
float var2
int var3
}MypackedStruct __attribute__((packed));
The attribute is in the wrong place, it should be associated with the
structure, not the type name.

} __attribute__((packed)) MypackedStruct;

--
cburgess@qnx.com

Randy Aeberhardt

Re: how to Pack structure ?

Post by Randy Aeberhardt » Tue Jun 25, 2002 12:10 am

Try "-fpack-struct" on the command line. Packs everything.

--
Randy Aeberhardt
<raeberhardt@tantalus-systems.com>
<www.tantalus-systems.com>

"Yasmine" <y.leroux@nospam.actris.com> wrote in message
news:aait87$hs6$1@inn.qnx.com...
Hi,

I would like to pack a structure

i tried

typedef struct {
char var1
float var2
int var3
}MypackedStruct __attribute__((packed));

but seems to do anything better than without the attribute.

I run QNX6RTP with qcc

Any idea ?

Jeff Baker

Re: how to Pack structure ?

Post by Jeff Baker » Tue Jun 25, 2002 1:30 pm

You could also take a look at #pragma pack().
Try "-fpack-struct" on the command line. Packs everything.

--
Randy Aeberhardt
raeberhardt@tantalus-systems.com
www.tantalus-systems.com

"Yasmine" <y.leroux@nospam.actris.com> wrote in message
news:aait87$hs6$1@inn.qnx.com...
Hi,

I would like to pack a structure

i tried

typedef struct {
char var1
float var2
int var3
}MypackedStruct __attribute__((packed));

but seems to do anything better than without the attribute.

I run QNX6RTP with qcc

Any idea ?



Thomas Emberso

Re: how to Pack structure ?

Post by Thomas Emberso » Tue Jun 25, 2002 2:15 pm

Jeff Baker <jbaker@qnx.com> wrote:
You could also take a look at #pragma pack().
Yes, -fpack-struct is a big 5lb sledge hammer. I am workng on a
fairly large project with a common makefile, and lots of inter
process communication. When we added -fpack-struct for communication
to the uControllers, and wierd things started to break, IIRC, the
resource manager app started and the UI app developed very interesting
issues. Escpecially the Photon app!

We now use

#define PACK __attribute__((packed))

and

typedef struct PACK
{
..stuff..
}

for the structures that require packing.

I guess th big difference is where the __attribute__ is located. Try
moving it before the members.

Tom
i tried

typedef struct {
char var1
float var2
int var3
}MypackedStruct __attribute__((packed));

but seems to do anything better than without the attribute.

I run QNX6RTP with qcc

Any idea ?

Post Reply

Return to “qdn.public.qnxrtp.applications”