| re: a strange problem with pointers
> the strange thing is that when I did that from the second member in[color=blue]
> the array I had a move of 1 byte in memory as you can see below :
> here you can see the adress in memory where each variable sits .[/color]
I think your problem here is padding in the structure. c is allowed to pad
any bits in the structure (cant remember the exact definition). The
practicalities of this usually mean that each new type will be stored in the
next boundary (usually 4 or 8 Bytes). This can usually be changed with your
compiler options but your code will change to take this into account.
The main problem is that your big struct has sub-structs within but the
sub-struct's first and last members are chars. These will be aligned in
memory until the long comes along - then padding will come in.
Ways around this - the easiest way would be to make the big structs have the
long variable at the end but you say you cant change the big struct.
The only other way I can see this working is if you use two sub structs, the
first for the first chars of your sub-struct and the second for the long and
remaining chars, e.g.
typedef struct strct1{
char a[9];
char b[8];
char c[6];
char d[8];
} sub1_struct;
typedef struct strct2{
long e;
char f;
char g[8];
char h;
char i;
char j;
char k;
}sub2_struct;
Now if you assign your pointers, you should (hopefully) get the proper
alignment
HTH
Allan |