> 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?
The same aligment as it used inside user space and kernel space - the code is
produced by different compilers (C/C++) - for the shared memory regions and for
there local copies of this inside user space and kernel space again. I want to
use memcpy (but this is another thread) to copy from shm region into a local
copy. The sizeof operator gives me the same size all the time. I'm not sure (I
lost the overview/believe what's true and what's not - I'm bug hunting ...) if
this has the same size at runtime in the memory due to aligment. memcpy() copies
bytewise memchunks trought the memory - how does it affected by different
aligns? I would say no. The start of this discuss was the contribution from
"Rus V. Brushkoff" <[EMAIL PROTECTED]>:
>> ... It should be noted that using
>> -malign-double option can lead to different struct fields aligning, even
>> in the same app.
If this happens I'm on the wrong site of the sun. My basic question was which
option has more priority, the compiler cmd line option -align-double or the
directive __attribute__ ((aligned)) xx_t, has the structure allways the same
size (even producted by different GNU compilers) and the same byte order
(should be due to memcpy()).
> 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.
I agree, but see above.
[...]
> 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.
I understood that.
> 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.
It's clear as well. Please have a look to the following example:
----8<-----
typedef unsigned short uint16; /* sizeof (uint16) must == 2 */
typedef unsigned int uint32; /* sizeof (uint32) must == 4 */
typedef struct {
char c;
uint32 ui32;
struct {
uint16 ui16[2];
} s1_t;
} x1_t;
typedef struct {
char c;
uint32 ui32;
struct s2 {
uint16 ui16[2];
};
} x2_t;
typedef struct {
char c;
uint32 ui32;
struct s3 {
uint16 ui16[2];
} s3_t;
} __attribute__((packed)) x3_t;
typedef struct {
char c;
uint32 ui32;
struct {
uint16 ui16[2];
} s4_t;
} __attribute__ ((aligned)) x4_t;
typedef struct {
char c;
uint32 ui32;
struct {
uint16 ui16[2];
} s5_t;
} __attribute__ ((aligned (4))) x5_t;
typedef struct {
char c;
uint32 ui32;
struct {
uint16 ui16[2];
} s6_t;
} __attribute__ ((aligned (8))) x6_t;
....
----8<-----
gcc -Wall struct_size.c -O6 -o struct_size && ./struct_size
sizeof(x1_t) = 12
sizeof(x2_t) = 8
sizeof(x3_t) = 9
sizeof(x4_t) = 12
sizeof(x5_t) = 12
sizeof(x6_t) = 16
gcc -Wall struct_size.c -O6 -malign-double -o struct_size && ./struct_size
sizeof(x1_t) = 12
sizeof(x2_t) = 8
sizeof(x3_t) = 9
sizeof(x4_t) = 16
sizeof(x5_t) = 12
sizeof(x6_t) = 16
At first it's seems the compiler option -malign-double overides the
attributes, it's important to know. Secondly why is there a difference between
x1_t and x2_t ?? (it's interesting for me)
What does the different offsets mean for the programer (like me)? I guess, the
compiler has to be responsible that I get by acess on xX.sX_t.ui16[0] allways
the same value at all options and attributes.
So on what case is the statement from Rus bounded??
Olaf
-- [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/