digitalmars.D - win32 and struct aligment
- bobef (19/19) Jun 02 2005 I have the folloing problem: in win32 headers NMPGSCROLL structure is de...
- Brad Beveridge (10/38) Jun 02 2005 I think that all pointers will have to be alignof == 4 (at least on x86
- bobef (4/44) Jun 02 2005 I can't understand the question... Mixture of bad english and bad D...
- Brad Beveridge (15/24) Jun 02 2005 Hmm, all members of a struct should have the property "offsetof"
- bobef (10/34) Jun 02 2005 struct RECT
- Andrew Fedoniouk (22/61) Jun 02 2005 typedef struct {
- bobef (3/68) Jun 02 2005 MSDN says it is BOOL but it is WORD in the ms platform sdk 2003 headers....
- Regan Heath (11/49) Jun 02 2005 I've had a number of these problems, I think it's just none of those
- Regan Heath (3/58) Jun 02 2005 Erg ... "none" == "one" (cold fingers, early morning..)
- bobef (17/71) Jun 02 2005 How to print the aligment in C? Also DMC headers miss the pager control ...
-
Regan Heath
(28/112)
Jun 02 2005
#include
- Regan Heath (20/104) Jun 02 2005 I also noted in the MSVC header richedit.h, this:
- Andrew Fedoniouk (4/26) Jun 02 2005 Check alignment of NMHDR.
- Walter (17/36) Jun 02 2005 defined as
- Andrew Fedoniouk (3/46) Jun 02 2005 Good one!
- bobef (8/59) Jun 03 2005 Good one but it still works the same (wrong) way...
- Walter (7/14) Jun 03 2005 It works (i.e. produces the same result) as the C compiler's alignment
- Brad Beveridge (5/17) Jun 03 2005 If the windows header doesn't specify something like pragma(pack...),
- bobef (7/11) Jun 04 2005 I am not using it because it doesn't work or at least I don't know how t...
I have the folloing problem: in win32 headers NMPGSCROLL structure is defined as align(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is 4. Also if I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?
Jun 02 2005
bobef wrote:I have the folloing problem: in win32 headers NMPGSCROLL structure is defined as align(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is 4. Also if I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?I think that all pointers will have to be alignof == 4 (at least on x86 32 bit machines), so it makes sense that NMPGSCROLL *s has alignof 4, also it makes sense that if lParam is actually a pointer then its lowest 2 bits will be zero - ie, it is also aligned on 4 byte boundrys. My only thoughts are 1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent 2) do the s.iScroll.offsetof, etc, numbers add up? Brad
Jun 02 2005
no property 'offsetof' for type 'int' This is what I get....1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParentI can't understand the question... Mixture of bad english and bad D... In article <d7nkfi$227p$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:I have the folloing problem: in win32 headers NMPGSCROLL structure is defined as align(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is 4. Also if I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?I think that all pointers will have to be alignof == 4 (at least on x86 32 bit machines), so it makes sense that NMPGSCROLL *s has alignof 4, also it makes sense that if lParam is actually a pointer then its lowest 2 bits will be zero - ie, it is also aligned on 4 byte boundrys. My only thoughts are 1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent 2) do the s.iScroll.offsetof, etc, numbers add up? Brad
Jun 02 2005
bobef wrote:no property 'offsetof' for type 'int' This is what I get....Hmm, all members of a struct should have the property "offsetof" http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
Jun 02 2005
struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....Hmm, all members of a struct should have the property "offsetof" http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
Jun 02 2005
typedef struct { NMHDR hdr; BOOL fwKeys; // <<<<<<<<<<<<<<<<< RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; }NMPGSCROLL, BOOL is not WORD. align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; // <<<<<<<<<<<<<<<<<< RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } "bobef" <bobef_member pathlink.com> wrote in message news:d7nqij$28cl$1 digitaldaemon.com...struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....Hmm, all members of a struct should have the property "offsetof" http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
Jun 02 2005
MSDN says it is BOOL but it is WORD in the ms platform sdk 2003 headers... Both of them doesn't work :) In article <d7nrme$29cl$1 digitaldaemon.com>, Andrew Fedoniouk says...typedef struct { NMHDR hdr; BOOL fwKeys; // <<<<<<<<<<<<<<<<< RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; }NMPGSCROLL, BOOL is not WORD. align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; // <<<<<<<<<<<<<<<<<< RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } "bobef" <bobef_member pathlink.com> wrote in message news:d7nqij$28cl$1 digitaldaemon.com...struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....Hmm, all members of a struct should have the property "offsetof" http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
Jun 02 2005
I've had a number of these problems, I think it's just none of those things that happens when you port from C to D. The way I go about solving them is by printing the alignment, offset and size of every member of the struct using D, then doing the same using C. One important point to note is that your D code is linking with the DMC libraries so if the struct you are using comes from within a DMC library you should really use DMC to compile your C. (I got bit by the differences between findfirst in MSVC and DMC) Regan On Thu, 2 Jun 2005 20:35:31 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....Hmm, all members of a struct should have the property "offsetof" http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
Jun 02 2005
On Fri, 03 Jun 2005 08:55:14 +1200, Regan Heath <regan netwin.co.nz> wrote:I've had a number of these problems, I think it's just none of those things that happens when you port from C to D.Erg ... "none" == "one" (cold fingers, early morning..) ReganThe way I go about solving them is by printing the alignment, offset and size of every member of the struct using D, then doing the same using C. One important point to note is that your D code is linking with the DMC libraries so if the struct you are using comes from within a DMC library you should really use DMC to compile your C. (I got bit by the differences between findfirst in MSVC and DMC) Regan On Thu, 2 Jun 2005 20:35:31 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....Hmm, all members of a struct should have the property "offsetof" http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
Jun 02 2005
How to print the aligment in C? Also DMC headers miss the pager control so I write it myself and I guess I will end up with the same problem in C. I've downloaded some japanese windows api translation and it was done in the same way I did it. I don't if they made it work. align(1): struct _16 { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } alias _16 NMPGSCROLL; alias _16* LPNMPGSCROLL; In article <opsrrgecsx23k2f5 nrage.netwin.co.nz>, Regan Heath says...I've had a number of these problems, I think it's just none of those things that happens when you port from C to D. The way I go about solving them is by printing the alignment, offset and size of every member of the struct using D, then doing the same using C. One important point to note is that your D code is linking with the DMC libraries so if the struct you are using comes from within a DMC library you should really use DMC to compile your C. (I got bit by the differences between findfirst in MSVC and DMC) Regan On Thu, 2 Jun 2005 20:35:31 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....Hmm, all members of a struct should have the property "offsetof" http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
Jun 02 2005
On Thu, 2 Jun 2005 21:20:49 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:How to print the aligment in C?#include <stdlib.h> #include <stdio.h> #define print_member(base,x) { printf(#x"%*s = (%02d) 0x%08x-0x%08x,%d\n",10-strlen(#x),"",(int)&x-(int)&base,&x,((int)&x)+siz of(x)-1,sizeof(x)); } typedef struct test { int a; short b; char c; } TEST; void main() { TEST tmp; print_member(tmp,tmp.a); print_member(tmp,tmp.b); print_member(tmp,tmp.c); } replace TEST with the struct to test.Also DMC headers miss the pager control so I write it myself and I guess I will end up with the same problem in C.Wrote it in C? then compiled to a lib? or.. what did you compile it with?I've downloaded some japanese windows api translation and it was done in the same way I did it. I don't if they made it work. align(1): struct _16 { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } alias _16 NMPGSCROLL; alias _16* LPNMPGSCROLL;I would have preferred (not that it makes a difference): struct NMPGSCROLL { ..etc.. } alias NMPGSCROLL* LPNMPGSCROLL; ReganIn article <opsrrgecsx23k2f5 nrage.netwin.co.nz>, Regan Heath says...I've had a number of these problems, I think it's just none of those things that happens when you port from C to D. The way I go about solving them is by printing the alignment, offset and size of every member of the struct using D, then doing the same using C. One important point to note is that your D code is linking with the DMC libraries so if the struct you are using comes from within a DMC library you should really use DMC to compile your C. (I got bit by the differences between findfirst in MSVC and DMC) Regan On Thu, 2 Jun 2005 20:35:31 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....Hmm, all members of a struct should have the property "offsetof" http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
Jun 02 2005
I also noted in the MSVC header richedit.h, this: #ifdef _WIN32 #else #endif where _WPAD is used in the: typedef struct _nmhdr { HWND hwndFrom; _WPAD _wPad1; UINT idFrom; _WPAD _wPad2; UINT code; _WPAD _wPad3; } NMHDR; struct. Regan On Thu, 2 Jun 2005 21:20:49 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:How to print the aligment in C? Also DMC headers miss the pager control so I write it myself and I guess I will end up with the same problem in C. I've downloaded some japanese windows api translation and it was done in the same way I did it. I don't if they made it work. align(1): struct _16 { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } alias _16 NMPGSCROLL; alias _16* LPNMPGSCROLL; In article <opsrrgecsx23k2f5 nrage.netwin.co.nz>, Regan Heath says...I've had a number of these problems, I think it's just none of those things that happens when you port from C to D. The way I go about solving them is by printing the alignment, offset and size of every member of the struct using D, then doing the same using C. One important point to note is that your D code is linking with the DMC libraries so if the struct you are using comes from within a DMC library you should really use DMC to compile your C. (I got bit by the differences between findfirst in MSVC and DMC) Regan On Thu, 2 Jun 2005 20:35:31 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....Hmm, all members of a struct should have the property "offsetof" http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
Jun 02 2005
Check alignment of NMHDR. Andrew. "bobef" <bobef_member pathlink.com> wrote in message news:d7nk3e$21qj$1 digitaldaemon.com...I have the folloing problem: in win32 headers NMPGSCROLL structure is defined as align(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is 4. Also if I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?
Jun 02 2005
"bobef" <bobef_member pathlink.com> wrote in message news:d7nk3e$21qj$1 digitaldaemon.com...I have the folloing problem: in win32 headers NMPGSCROLL structure isdefined asalign(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is4. Alsoif I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?If you want the *members* to be aligned a certain way, rather than the struct itself, put the align directive inside the struct: struct NMPGSCROLL { align(1): NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; }
Jun 02 2005
"Walter" <newshound digitalmars.com> wrote in message news:d7nv6c$2cgp$1 digitaldaemon.com..."bobef" <bobef_member pathlink.com> wrote in message news:d7nk3e$21qj$1 digitaldaemon.com...Good one!I have the folloing problem: in win32 headers NMPGSCROLL structure isdefined asalign(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is4. Alsoif I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?If you want the *members* to be aligned a certain way, rather than the struct itself, put the align directive inside the struct: struct NMPGSCROLL { align(1): NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; }
Jun 02 2005
In article <d7ob83$2li3$1 digitaldaemon.com>, Andrew Fedoniouk says..."Walter" <newshound digitalmars.com> wrote in message news:d7nv6c$2cgp$1 digitaldaemon.com...Good one but it still works the same (wrong) way... Can't I realign it myself? something like char[4] a=cast(char[4])s.iScroll and then change bytes positions? I don't have any idea what this aligment thing is and what is it's use except it is ruining my code :)"bobef" <bobef_member pathlink.com> wrote in message news:d7nk3e$21qj$1 digitaldaemon.com...Good one!I have the folloing problem: in win32 headers NMPGSCROLL structure isdefined asalign(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is4. Alsoif I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?If you want the *members* to be aligned a certain way, rather than the struct itself, put the align directive inside the struct: struct NMPGSCROLL { align(1): NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; }
Jun 03 2005
"bobef" <bobef_member pathlink.com> wrote in message news:d7p8fh$9qe$1 digitaldaemon.com...Good one but it still works the same (wrong) way...It works (i.e. produces the same result) as the C compiler's alignment directives on the same struct.Can't I realign it myself? something like char[4] a=cast(char[4])s.iScroll and then change bytes positions????I don't have any idea what this aligment thing is and what is it's useexcept itis ruining my code :)Why are you using it? Exactly what are you trying to achieve?
Jun 03 2005
Walter wrote:"bobef" <bobef_member pathlink.com> wrote in messageIf the windows header doesn't specify something like pragma(pack...), then that structure won't be tightly packed I don't think - in which case, telling D to pack the structure may be a bit broken :) BradI don't have any idea what this aligment thing is and what is it's useexcept itis ruining my code :)Why are you using it? Exactly what are you trying to achieve?
Jun 03 2005
In article <d7qql5$1j2t$1 digitaldaemon.com>, Walter says...I am not using it because it doesn't work or at least I don't know how to make it work, but I need it because I need a Pager Control and definition of NMPGSCROLL, or whatever it was, in the ms headers have #include <pshpack1.h> and #include <poppack.h> around it, which says #pragma(pack,1), which I believe, should be equivalent of D's align(1). This is why. But all numbers are messed up! damn.I don't have any idea what this aligment thing is and what is it's useexcept itis ruining my code :)Why are you using it? Exactly what are you trying to achieve?
Jun 04 2005