On Mon, 14 May 2007 16:24:59 +0000, J HU wrote: > Dear all, > > Perhaps it's an easy/silly question but I don't understand how it works. > > (I'm working in a debian) > I have declared a structure and I'm using the "sizeof" to get the size of > this structure. > > After the call I get that the total size is 64Bytes but if I get the size of > each field and I add them manually I get that it should be 61Bytes... > > Anyone knows why the result is not the same? > > Thanks in advance > > Javi > Because sizeof is not really the size of the struct, it is the distance between adjacent structs in an array. Alignment forces the extra bytes.
In my opinion, 'sizeof' should have been called 'spacingof', and there should have been other properties for alignment, such as sizeof, modulusof. and remainderof, so you could do your own storage allocation calculations in a machine-independent way. Something could take sizeof bytes starting at an address that is remainderof bytes past a n address that is a multiple of modulusof. The log2 of modulus would also be useful. -- hendrik -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]