Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 01, 2004 struct.<field>.offsetof | ||||
---|---|---|---|---|
| ||||
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 struct.<field>.offsetof is not supported. struct.html: # Struct Field Properties # .offsetof # Offset in bytes of field from beginning of struct test case: http://svn.kuehne.cn/dstress/run/offsetof_01.d Thomas -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.9.12 (GNU/Linux) iD8DBQFBrbmj3w+/yD4P9tIRAvcRAKCsI0/P2vAYfUTvhOigxttiAohFZACffZw2 ZD7QR3yzwbiCZP6qiw7dB9o= =UpiQ -----END PGP SIGNATURE----- |
December 01, 2004 Re: struct.<field>.offsetof | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | On Wed, 1 Dec 2004 13:31:31 +0100, Thomas Kuehne <thomas-dloop@kuehne.thisisspam.cn> wrote: > struct.<field>.offsetof is not supported. > > struct.html: > # Struct Field Properties > # .offsetof > # Offset in bytes of field from beginning of struct > > test case: > http://svn.kuehne.cn/dstress/run/offsetof_01.d Try this instead: // $HeadURL$ // $Date$ // $Author$ module dstress.run.offsetof_01; struct MyStruct{ int a; int b; } int main(){ assert(MyStruct.a.offsetof >= 0); assert(MyStruct.b.offsetof >= 0); assert(MyStruct.a.offsetof != MyStruct.b.offsetof); return 0; } IIRC this property applies to the struct definition *not* the struct instance. Regan |
December 01, 2004 Re: struct.<field>.offsetof | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Regan Heath schrieb am Thu, 02 Dec 2004 09:54:55 +1300: > On Wed, 1 Dec 2004 13:31:31 +0100, Thomas Kuehne >> struct.<field>.offsetof is not supported. >> >> struct.html: >> # Struct Field Properties >> # .offsetof >> # Offset in bytes of field from beginning of struct >> >> test case: >> http://svn.kuehne.cn/dstress/run/offsetof_01.d > > Try this instead: > > // $HeadURL$ > // $Date$ > // $Author$ > > module dstress.run.offsetof_01; > > struct MyStruct{ > int a; > int b; > } > > int main(){ > assert(MyStruct.a.offsetof >= 0); > assert(MyStruct.b.offsetof >= 0); > assert(MyStruct.a.offsetof != MyStruct.b.offsetof); > > return 0; > } > > IIRC this property applies to the struct definition *not* the struct instance. That's strange. For classes it's the other way round: the property applies only to the instance and not the class definition !? I can come up with an explanation why - under some uncommon circumstances - the offsetof property can only be determined for instances. Why should a property that is available for the definition not be available for the instance? Thomas -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.9.12 (GNU/Linux) iD8DBQFBrjLz3w+/yD4P9tIRAgEtAJ4y/5o8mo8+RP2Ux6YGsGWJ27msmQCfTVAP 0yvaME+kPAof7cYnmF3NdCI= =sfU0 -----END PGP SIGNATURE----- |
December 01, 2004 Re: struct.<field>.offsetof | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | On Wed, 1 Dec 2004 22:09:07 +0100, Thomas Kuehne <thomas-dloop@kuehne.thisisspam.cn> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Regan Heath schrieb am Thu, 02 Dec 2004 09:54:55 +1300: >> On Wed, 1 Dec 2004 13:31:31 +0100, Thomas Kuehne >>> struct.<field>.offsetof is not supported. >>> >>> struct.html: >>> # Struct Field Properties >>> # .offsetof >>> # Offset in bytes of field from beginning of struct >>> >>> test case: >>> http://svn.kuehne.cn/dstress/run/offsetof_01.d >> >> Try this instead: >> >> // $HeadURL$ >> // $Date$ >> // $Author$ >> >> module dstress.run.offsetof_01; >> >> struct MyStruct{ >> int a; >> int b; >> } >> >> int main(){ >> assert(MyStruct.a.offsetof >= 0); >> assert(MyStruct.b.offsetof >= 0); >> assert(MyStruct.a.offsetof != MyStruct.b.offsetof); >> >> return 0; >> } >> >> IIRC this property applies to the struct definition *not* the struct >> instance. > > That's strange. For classes it's the other way round: the property > applies only to the instance and not the class definition !? > > I can come up with an explanation why - under some uncommon > circumstances - the offsetof property can only be determined for > instances. For classes but not for structs. For structs you are supposed to be able to align and lay them out how you want. So at compile time the offsets are known. I suspect that is why the definition is used for structs and the instance for classes. > Why should a property that is available for the definition not be > available for the instance? Good question. If it's available for the definition then surely it can be made available for the instance.. it might be an optimisation thing, why store the info 'in' the struct when it's not required. However surely some compiler trickery could deduce the struct type from the instance and turn.. struct foobar { int a; } foobar b; b.a.offsetof into.. struct foobar { int a; } foobar b; foobar.a.offsetof Regan > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.9.12 (GNU/Linux) > > iD8DBQFBrjLz3w+/yD4P9tIRAgEtAJ4y/5o8mo8+RP2Ux6YGsGWJ27msmQCfTVAP > 0yvaME+kPAof7cYnmF3NdCI= > =sfU0 > -----END PGP SIGNATURE----- |
Copyright © 1999-2021 by the D Language Foundation