S
Stephen Sprunk
struct a
{
int b;
char a;
int c;
}
On i386 the sizeof this structure would be 12 bytes,as 3 bytes are
padded after a so that c is aligned on 4byte boundary.
No, on your particular implementation it's 12 bytes. On other
implementations (including the same compiler with different flags) it may be
another value. In particular, 6 and 24 are ones you're likely to see, but
there are other possibilities as well, even on x86 machines.
So the doubts that i have is
That's a question, not a doubt.
1) Does the poratbility issue come into play only when i persist this
structure on one architecture ( for ex i386) and try to read the
structure back on a different architecture(for ex motorola series)
If you mean write the structure to a file as a single binary object, then
try to read it as a structure on another implementation, that will cause you
a world of headaches in the real world. The sizes, padding, and
representation (including endianness in particular) of those types can all
vary by implementation.
The C FAQ covers all of this. Please go read it.
S