std C/C++ and packed

David Scott Page page at cs.utexas.edu
Fri Apr 26 16:52:43 EDT 2002


Hi,

This is the last error message to conquer (although there are a few
warnings that I'd like to look into when I get a chance).

In click/include/click/click_ether.h, fddi.h, and rfc1483.h, the
__GNUC__ __attribute__ ((packed)) is appled to structures describing
wire syntax. While one field of the fddi.h structures needs packing,
it seems packed is gratuitously used on the others. Regarding the
structure as a whole (e.g., access via a reinterpret_cast):

1) Do these serve any purpose on x86, ppc, etc. architectures that
provide hardware support for misaligned accesses?  I think you can
specify stricter alignment (e.g., align everything to a double's
boundary) as a compiler flag even on such architectures, but I didn't
notice this flag being used to compile click.

2) Sans a dose of click-align, sparc bus-error's anyway, even on
test.click, hence specifying packed on any naturally packed structures
seems like it could lead to an unnecessary performance degradation.

The fourth file enjoying attribute packed is
click/elements/etherswitch/bridgemessage.hh.  In this case a
CLICKED_PACKED macro is defined and applied to specific fields needing
to be packed (seems like a candidate for config.h or glue.hh).

So, how to resolve in general?  (On Solaris, I just commented out the
attribute, when compiling with KCC, applied click-align, and didn't
use fddi or bridgemessage).

The Sun compiler has a #pragma packed and a -misalign flag that I
might be able to figure out how to get through KCC. Alternatively, if
the bridgemessage style of packing was used in the other files, for my
purposes (ethernet), I could get away with just defining it to empty.

Suggestions?

--
Scott Page




More information about the click mailing list