Hi, Lee Kirby!
On 23 Dec 97 22:57:42 you wrote to All
LK> I'm very new to C++, and can't figure out why I get two extra bytes
LK> when I write this structure to a file:
LK> struct fidoMsg::fMsg {
...
LK> } msg;
LK> ...via:
LK>
LK> outfile.write( msg, sizeof( fMsg ) );
LK> The way I count, this structure should be only 190 bytes, but if I do
LK> a sizeof( fMsg), it reports 192!
What compiler do you use? The structure members may get "packed", adjusted to
appear on word or dword boundaries. Or the structure is padded to have size
multiple of 2, 4, 8, etc. This make access to members faster on most
processors, while on others you _must_ align some entities to be accessible.
(For example on SPARC or PA-RISC processors if you try to read a long that is
not aligned on an address multiple of 4, you get a bus error and a coredump.
:)
Many current compilers have #pragma pack() that let the programmer
controlmember alignment in the functions, but they work differently in the
different compilers and even in slightly different versions of the same
comiler. There may be also be switches to the comiler for a global setting.
Paul
... ERROR LPT1 not found.. use backup - PENCIL & PAPER
--- GNU/Linux
---------------
* Origin: The FlintStones' Cave in BedRock (2:371/20.2)
|