std C/C++ patch #9

David Scott Page page at cs.utexas.edu
Mon Apr 29 14:59:35 EDT 2002


Eddie,

Sun CC/cc implements #pragma pack(), with effect similar to gcc's
__attribute__((packed)), and which KCC standardly ignores (passing it
on to the cc backend); however:

1) #pragma can not be generated from a macro (per gcc.info), and Sun
does not yet implement the C99 _Pragma operator;

2) truly misaligned or packed structures require a -misalign compiler
flag that implements *all* loads and stores via pointers into
single-byte loads and stores, killing performance (Sun call this
"conservative").

Considering the above, and that KCC, Sun CC, and g++ on Solaris all
generate #pragma-free code satisfying your sizeof criteria (category
1, below) for ether, ip, etc., and only the mal-defined fddi structure
fails the field alignment critera (category 2), for now, I think a
reasonable approach is to implement bridgemessage.h's CLICKED_PACK
macro in glue.h, and enable it via __GNUC__. For the motivated, a test
in configure could be used to warn non-gcc users; instead of the
current fatal #error in the C source.

Barring this or a more creative solution, I'll just comment them out.

--
Scott Page

> It seems to me like we need to figure out two things for
> __attribute__((packed)):
> 
> 1. What to do about sizeof(click_ether)?
> 
>    It would be OK, but very annoying, to deprecate sizeof(click_ether), I
>    suppose -- and, similarly, sizoef(click_ip), etc. -- and move to some
>    macro convention. :P
> 
> 2. What about structures that actually need to be packed (i.e., they
>    contain unaligned uint32_ts et al.)?
> 
>    I don't want to fix this one without help from the compiler. One could
>    write lovely macros for accessing unaligned integers, but, in a word,
>    barf.
> 
> I think what I'd like to do here is wait to see if the relevant compilers
> support what we need. Does KCC/Sun CC have a #pragma that would let
> sizeof(click_ether) == 14, and allow unaligned accesses within a particular
> kind of structure? If so, we'll need to decide on a set of macros that
> work on any compiler.
> 
> Eddie
> 




More information about the click mailing list