digitalmars.D.bugs - DMD .120 sizeof struct bug
- dickl (16/16) Apr 08 2005 This appeared in .120 and worked in previous versions
- Thomas Kuehne (12/28) Apr 08 2005 -----BEGIN PGP SIGNED MESSAGE-----
- Walter (13/17) Apr 09 2005 D was changed to match C's behavior, which gives 8 as well:
This appeared in .120 and worked in previous versions The size of the struct should be 5 but is returned as 8. Changing the struct to "align(1) struct foo" gives the correct answer. This has implications when passing structures to the Windows api. ------------------------------------- private import std.stdio; struct foo { uint cbSize; char j; } int main() { uint k=foo.sizeof; // k should be 5 but foo.sizeof returns 8 return 0; }
Apr 08 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 dickl schrieb am Fri, 08 Apr 2005 23:00:53 -0400:This appeared in .120 and worked in previous versions The size of the struct should be 5 but is returned as 8. Changing the struct to "align(1) struct foo" gives the correct answer. This has implications when passing structures to the Windows api. ------------------------------------- private import std.stdio; struct foo { uint cbSize; char j; } int main() { uint k=foo.sizeof; // k should be 5 but foo.sizeof returns 8 return 0; }Seems to be missing from the changelog - this was documented in the source code. I'm not sure that this solution to the GC problem is wise. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCV3cL3w+/yD4P9tIRAvOsAKCCzog/d0dhZId82F5Ag5PnpDYuxQCaAr6x sLwhmqj64915CQYYTK2UgaM= =QtSP -----END PGP SIGNATURE-----
Apr 08 2005
"dickl" <dick221z yahoo.com> wrote in message news:d37gh6$v1i$1 digitaldaemon.com...This appeared in .120 and worked in previous versions The size of the struct should be 5 but is returned as 8. Changing the struct to "align(1) struct foo" gives the correct answer. This has implications when passing structures to the Windows api.D was changed to match C's behavior, which gives 8 as well: #include <stdio.h> struct foo { unsigned cbSize; char j; }; void main() { printf("%d\n", sizeof(struct foo)); // prints 8 }
Apr 09 2005
Walter wrote:"dickl" <dick221z yahoo.com> wrote in message D was changed to match C's behavior, which gives 8 as well:True. C:\> cl program.c C:\> program 8 and: C:\> cl -Zp1 program.c C:\> program 5 -Zp{n} should be available in D. DMD has not enough switches...
Apr 09 2005
Its fine as long as I know what it is doing and how to work around. However, the code is from Microsoft DDK so the Microsoft compiler is returning 5 rather than 8 and of course Windows was expecting 5. Walter wrote:"dickl" <dick221z yahoo.com> wrote in message news:d37gh6$v1i$1 digitaldaemon.com...This appeared in .120 and worked in previous versions The size of the struct should be 5 but is returned as 8. Changing the struct to "align(1) struct foo" gives the correct answer. This has implications when passing structures to the Windows api.D was changed to match C's behavior, which gives 8 as well: #include <stdio.h> struct foo { unsigned cbSize; char j; }; void main() { printf("%d\n", sizeof(struct foo)); // prints 8 }
Apr 09 2005
"dickl" <dick221z yahoo.com> wrote in message news:d38rub$kvh$1 digitaldaemon.com...Its fine as long as I know what it is doing and how to work around. However, the code is from Microsoft DDK so the Microsoft compiler is returning 5 rather than 8 and of course Windows was expecting 5.Check the DDK code - I bet there's a #pragma pack(1) around the struct declaration, which works like D's align(1).
Apr 09 2005