tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Improving the data supplied by BPF



On Fri, Dec 26, 2008 at 10:13:00AM -0500, Christos Zoulas wrote:
> On Dec 25, 11:45pm, lacombar%gmail.com@localhost ("Arnaud Lacombe") wrote:
> | btw, why is the current `struct bpf_hdr' not packed ? this would avoid
> | the SIZEOF_BPF_HDR hack...
> 
> packing a structure should be avoided when we can force optimal packing
> by re-ordering members because it makes the code compiler neutral.

I don't think that you can force space-optimal packing by re-ordering
members, can you?  AFAIK, no standard forbids the compiler from
padding this struct,

struct x {
        uint64_t x;
        uint32_t y;
        uint16_t z;
        uint8_t w;
};

like this

struct x {
        uint64_t x;
        uint32_t y;
        uint32_t pad1;
        uint16_t z;
        uint16_t pad2;
        uint32_t pad3;
        uint8_t w;
        uint8_t pad4;
        uint16_t pad5;
        uint32_t pad6;
};

Ordinarily, I would qualify the struct x definition with __packed
__aligned(8) in order to get the close-packed binary format that
I desired.

Dave

-- 
David Young             OJC Technologies
dyoung%ojctech.com@localhost      Urbana, IL * (217) 278-3933


Home | Main Index | Thread Index | Old Index