public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: gcc 3.4.2 + fpack-struct + hash_map
       [not found] <200503231554.j2NFsvPZ025925@inbound-smtp-2.corp.adobe.com>
@ 2005-03-23 16:40 ` Eljay Love-Jensen
  2005-03-23 17:08   ` Thierry MARTIN
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Eljay Love-Jensen @ 2005-03-23 16:40 UTC (permalink / raw)
  To: Thierry MARTIN, gcc-help

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: gcc 3.4.2 + fpack-struct + hash_map
  2005-03-23 16:40 ` gcc 3.4.2 + fpack-struct + hash_map Eljay Love-Jensen
  2005-03-23 17:08   ` Thierry MARTIN
@ 2005-03-23 17:08   ` Thierry MARTIN
       [not found]   ` <200503231647.j2NGlfPZ002441@inbound-smtp-2.corp.adobe.com>
  2 siblings, 0 replies; 6+ messages in thread
From: Thierry MARTIN @ 2005-03-23 17:08 UTC (permalink / raw)
  To: 'Eljay Love-Jensen', gcc-help

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




^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: gcc 3.4.2 + fpack-struct + hash_map
  2005-03-23 16:40 ` gcc 3.4.2 + fpack-struct + hash_map Eljay Love-Jensen
@ 2005-03-23 17:08   ` Thierry MARTIN
  2005-03-23 17:08   ` Thierry MARTIN
       [not found]   ` <200503231647.j2NGlfPZ002441@inbound-smtp-2.corp.adobe.com>
  2 siblings, 0 replies; 6+ messages in thread
From: Thierry MARTIN @ 2005-03-23 17:08 UTC (permalink / raw)
  To: 'Eljay Love-Jensen', gcc-help

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




^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: gcc 3.4.2 + fpack-struct + hash_map
       [not found]   ` <200503231647.j2NGlfPZ002441@inbound-smtp-2.corp.adobe.com>
@ 2005-03-23 18:44     ` Eljay Love-Jensen
  0 siblings, 0 replies; 6+ messages in thread
From: Eljay Love-Jensen @ 2005-03-23 18:44 UTC (permalink / raw)
  To: Thierry MARTIN, gcc-help

Hi Thierry,

>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.

Then if I were working on your QUICK-AND-DIRTY project, I'd instrument the code with the GCC __attribute__((packed)) on the network packet structures, and nothing else.  That would be the quick-and-dirty fix.

I stand by my earlier general advice to NOT pack those structures, and rather to make binary-format-savvy read/write routines.

But this is "quick and dirty".

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

You may need to rebuild the Standard C++ Library with pack turned on, since you are being indiscriminate with what is/isn't packed.

I presume you are using Intel based Linux, because other Linux platforms may or may not work with packed structures.

There is a non-trivial performance penalty with using packed structures, even on Intel architecture.

However, see next...

>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)..

I think that -fpack-struct will cause you more grief than my suggestion above to instrument the code's network packet structs.

>...and have my boss happy to migrate to the linux world ;-).

Can't argue with that.  :-)

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 6+ messages in thread

* gcc 3.4.2 + fpack-struct + hash_map
@ 2005-03-23 16:09 Thierry MARTIN
  0 siblings, 0 replies; 6+ messages in thread
From: Thierry MARTIN @ 2005-03-23 16:09 UTC (permalink / raw)
  To: gcc-help

Hi,

I have to build a program with g++ and fpack-struct option turned on.

1) version gcc 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)

2) testh.cpp

#include <ext/hash_map>
using namespace __gnu_cxx;

int main (int argc, char* argv[])
{
 hash_map<int, int> inttale;
 return 0;
}

3)The command line to build :
# g++ testh.cpp -fpack-struct

In file included from
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/ios:49,
                 from
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/ostream:4
5,
                 from
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/iterator:
71,
                 from
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/ext/hasht
able.h:69,
                 from
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/ext/hash_
map:65,
                 from testh.cpp:1:
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/bits/ios_
base.h:
In member function `std::_Ios_Fmtflags
std::ios_base::setf(std::_Ios_Fmtflags)':
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/bits/ios_
base.h:536:
error: cannot bind packed field
`((std::ios_base*)this)->std::ios_base::_M_flags' to
`std::_Ios_Fmtflags&'

(... to make it short :-) ) 

4)
 I know that I can apply a specific attribute to the structures that
have to be packed. May be a #pragma pack could also do the trick.

BUT: the program I have to build is made of hundred of source files
and has always been built with the pack-struct option. Thus it's a
very hard task to modify the sources and I would realy prefer a nicer
way to do it :-).

So, I am just looking for a good advice...

Thanks for your help !!


^ permalink raw reply	[flat|nested] 6+ messages in thread

* gcc 3.4.2 + fpack-struct + hash_map
@ 2005-03-23 16:09 Thierry MARTIN
  0 siblings, 0 replies; 6+ messages in thread
From: Thierry MARTIN @ 2005-03-23 16:09 UTC (permalink / raw)
  To: gcc-help

Hi,

I have to build a program with g++ and fpack-struct option turned on.

1) version gcc 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)

2) testh.cpp

#include <ext/hash_map>
using namespace __gnu_cxx;

int main (int argc, char* argv[])
{
 hash_map<int, int> inttale;
 return 0;
}

3)The command line to build :
# g++ testh.cpp -fpack-struct

In file included from
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/ios:49,
                 from
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/ostream:4
5,
                 from
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/iterator:
71,
                 from
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/ext/hasht
able.h:69,
                 from
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/ext/hash_
map:65,
                 from testh.cpp:1:
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/bits/ios_
base.h:
In member function `std::_Ios_Fmtflags
std::ios_base::setf(std::_Ios_Fmtflags)':
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/bits/ios_
base.h:536:
error: cannot bind packed field
`((std::ios_base*)this)->std::ios_base::_M_flags' to
`std::_Ios_Fmtflags&'

(... to make it short :-) ) 

4)
 I know that I can apply a specific attribute to the structures that
have to be packed. May be a #pragma pack could also do the trick.

BUT: the program I have to build is made of hundred of source files
and has always been built with the pack-struct option. Thus it's a
very hard task to modify the sources and I would realy prefer a nicer
way to do it :-).

So, I am just looking for a good advice...

Thanks for your help !!


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-03-23 17:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <200503231554.j2NFsvPZ025925@inbound-smtp-2.corp.adobe.com>
2005-03-23 16:40 ` gcc 3.4.2 + fpack-struct + hash_map Eljay Love-Jensen
2005-03-23 17:08   ` Thierry MARTIN
2005-03-23 17:08   ` Thierry MARTIN
     [not found]   ` <200503231647.j2NGlfPZ002441@inbound-smtp-2.corp.adobe.com>
2005-03-23 18:44     ` Eljay Love-Jensen
2005-03-23 16:09 Thierry MARTIN
  -- strict thread matches above, loose matches on Subject: below --
2005-03-23 16:09 Thierry MARTIN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).