gcc 3.4.2 + fpack-struct + hash_map

Thierry MARTIN thierry.martin@accellent-group.com
Wed Mar 23 17:08:00 GMT 2005


Hi Eljay,

Thanks for your answer.

I share your point of view regarding the use of pack structures. In our
case, pack structures are used for network packet decoding and the choice
was made to pack structure to make it simple and avoid errors.

My problem today is that I have an existing -*** complex ***- source code
(originally written under VC++), that has to run on a linux platform with a
recent version of gcc. 
Using the fpack-struct on this project would just be a way to get a running
version of my program in short time (no code changes, no specific tests),
and have my boss happy to migrate to the linux world ;-). 

So actually, I am rather looking for a work-around (or some backward
compatibility feature in gcc?). 

Best regards
Thierry


-----Message d'origine-----
De : Eljay Love-Jensen [mailto:eljay@adobe.com] 
Envoyé : mercredi 23 mars 2005 17:10
À : Thierry MARTIN; gcc-help@gcc.gnu.org
Objet : Re: gcc 3.4.2 + fpack-struct + hash_map

Hi Thierry,

>I am just looking for a good advice...

My good advice is to avoid packed structures.

For those few structures that "really need to be packed", I would first ask
"Why does this structure 'really need' to be packed?"

When the reason to pack the structure is compelling (and I've only seen two
cases for a compelling reason:  DMA required structure layout for audio
data, and pixmap layout) tag the structure with the appropriate
__attribute__((packed)) ... please see the GCC manual regarding the details
of this compiler directive.

A reason I have heard cited -- which I consider a completely BOGUS reason --
is file format layout.  In memory data structures should be constructed
(marshalled) from the file format layout, and be serialized when written to
the file format.  That means making binary-format-savvy read and
binary-format-savvy write routines.  Also, employ ntoh and hton routines to
help make the binary-format platform agnostic.  Regardless if it is to/from
a file format, or to/from over-the-wire communication.

Packed structures can be sensitive to platform constraints, and hence, make
the code not portable.  Tender Loving Care can help defuse this issue, but
that requires a HEAVY dose of CARE.

HTH,
--Eljay






More information about the Gcc-help mailing list