>>>>> "Olaf" == Olaf Petzold <[EMAIL PROTECTED]> writes:

 >> : So the best way is the way how did you suggested. Anyway is
 >> there a performance : factor to use unsigned char versus unsigned
 >> int ? I believe to remember that : one should use basic types (int
 >> and double) on performance programs ? Any : experience? I compiled
 >> the kernel program (written in C) with -align-double etc.
 >> 
 >> The perfomance difference not so significant, rewriting critical
 >> paths in asm is more effective usually. It should be noted that
 >> using -malign-double option can lead to different struct fields
 >> aligning, even in the same app.

 Olaf> Oh dear... Can I avoid this by using

 Olaf> typedef struct { flag_t inuse; flag_t valid; double um[65536] }
 Olaf> __attribute__ ((aligned)) shm_slut_t;

 Olaf> ??? Is it guarantee that all structures (inside shm, inside
 Olaf> local static copy, inside kernel space code produced by Gnu-C
 Olaf> and user space program compiled by Gnu-C++) have the same
 Olaf> aligment - even if compiled with the Option -align-double?

Same alignment as what?

If you compile the same structure declaration n times with the same
compiler alignment controls, for the same platform, it should produce
the same alignment.  That seems rather obvious; the compiler is broken 
if that fails.

If you change the structure, the offsets generally change; the changes 
should be predictable but they may not always be what you would
expect, because the rules aren't necessarily what you might think they 
are or should be.  The C standard does constrain the rules but doesn't 
nail them down fully.  In particular, compiler options may affect the
outcome, as may moving to another platform.

As far as I know (I'm not a language lawyer) these are the rules, in
the absence of "packed":

1. Fields must be in the declared order.
2. Each field is aligned on a multiple of its alignment.  Note that it 
does NOT have to be the smallest possible multiple of its alignment.
2a. The alignment of a primitive datatype is its size
2b. The alignment of a struct or union is the largest of the
alignments of its members (recursively)
3. The size of a struct or union is a multiple of the largest of the
alignments of its members.

So, if you have a struct that contains a char, a uint32, and a struct
of two uint16s, in that order.  If the minimum alignments are used,
the offsets will be 0, 4, and 8, with the inner structure having a
total length of 4 and its components are at offsets 8 and 10 from the
start of the outer struct.  The struct size is 12, which is a multiple 
of 4.

It would also be legal for everything to be rounded up to a multiple
of 8, making the inner struct size 16 (with alignment 8) and the outer 
struct having its fields at 0, 8, and 16, for a total size of 32.

        paul

-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to