M
MSReddy
Hi Group,
I have a structure than has other structures in it. I added 3 members
to a strucuture and my program started behaving very strangly. When I
printed sizes of the strucutures the values were very strange and
unexpected. Here is an example. Applogies for not being able to post
the exact code.
Struct B{
long b1;
short b2;
}
Struct C{
long c1;
char c2;
char *cptr;
}
Struct A{
long a1;
B sb;
long a2;
C sc;
short a3;
char *a4;
}
Now changes struct C to,
Struct C{
long c1;
char c2;
char c3;
char c4;
bool c5;
char *cptr;
}
Then I printed the sizes of my strucutures using sizeof(). These are
actual values from my program.
Before Modification:
Size of Struct A: 814552
Size of Struct C: 8452
After Modification,
Size of Struct A: 815064
Size of Struct C: 8460
Those values obviously looks spurious. I could not access the members
of Struct A correctly. All the members of Struct A declared after
Struct C (in this case a3 and *a4) were off by 256 bytes. I ran this
on two computers just to make sure it is not some strage problem with
machine and got same results.
How can I solve this. Any help is highly appreciated. Thank you very
much.
Reddy
I have a structure than has other structures in it. I added 3 members
to a strucuture and my program started behaving very strangly. When I
printed sizes of the strucutures the values were very strange and
unexpected. Here is an example. Applogies for not being able to post
the exact code.
Struct B{
long b1;
short b2;
}
Struct C{
long c1;
char c2;
char *cptr;
}
Struct A{
long a1;
B sb;
long a2;
C sc;
short a3;
char *a4;
}
Now changes struct C to,
Struct C{
long c1;
char c2;
char c3;
char c4;
bool c5;
char *cptr;
}
Then I printed the sizes of my strucutures using sizeof(). These are
actual values from my program.
Before Modification:
Size of Struct A: 814552
Size of Struct C: 8452
After Modification,
Size of Struct A: 815064
Size of Struct C: 8460
Those values obviously looks spurious. I could not access the members
of Struct A correctly. All the members of Struct A declared after
Struct C (in this case a3 and *a4) were off by 256 bytes. I ran this
on two computers just to make sure it is not some strage problem with
machine and got same results.
How can I solve this. Any help is highly appreciated. Thank you very
much.
Reddy