On Wed, 01 Aug 2007 15:34:56 -0700 adar <adar_ji DeleteThis @yahoo.com> wrote:
| I need to find out what is the size of following data structures in 8
| bit, 16 bit, 32 bit, and 64 bit systems.
|
| struct findsize{
|
| unsigned char chA;
| unsigned long lg;
| unsigned short sh;
| unsigned char chB;
| };
|
|
| sizeof() runs at compile time, that means one can know in advance what
| size of these. I don't have 8 bit or 16 bit systems. I do have 32 bit
| and 64 bit system.
|
| I believe, in 32 bit system, this would be 1+4+2+1 = 8 bytes.
|
| Can anyone throw some light here on how to find size?
The size can vary even between different systems of the same bit size.
If you need to know the size before compile, maybe you are also needing
to know the offset layout. Neither of these is a known until compile.
If you are trying to design a common way to communicate between programs
in different machine architectures, you should design structures in your
protocol independent of any machine. For example define fields as a
series of bytes in some order (big endian is the basic order for the
internet). Then code serializers and deserializers as functions to do
the grunt work.
--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
| first name lower case at ipal.net / spamtrap-2007-08-01-2015 DeleteThis @ipal.net |
|------------------------------------/-------------------------------------|