Hi Guys,
I am trying to make a simple STRUCT and I am finding that if I have a member 'Width' I get compilation errors.
Is 'Width' a reserved thing?
This wont compile
LLDXGI_MODE_DESC STRUCT
Width DWORD 0
Height DWORD 0
LLDXGI_MODE_DESC ENDS
But this will
LLDXGI_MODE_DESC STRUCT
someOtherWidth DWORD 0
Height DWORD 0
LLDXGI_MODE_DESC ENDS
Thanks :)
Quote from: Lonewolff on March 16, 2016, 05:02:27 PMIs 'Width' a reserved thing?
Yes, it's used with records. Use _Width instead - see Windows.inc for some examples.
Here is a keyword list, if you don't find it.
Cool. Thanks for the heads up :)
Having said that. If there is an item in the SDK that has a member 'width' and you prefix it as '_width', won't that break SDK compatibility and lead to further confusion?
Quote from: Lonewolff on March 17, 2016, 10:26:47 AM
Having said that. If there is an item in the SDK that has a member 'width' and you prefix it as '_width', won't that break SDK compatibility and lead to further confusion?
Inevitably! There are several examples in Windows.inc and elsewhere that use the "_" to overcome this problem:
SDK:
typedef struct NMLVSCROLL {
NMHDR hdr;
int dx;
int dy;
} NMLVSCROLL, *LPNMLVSCROLL;
Windows.inc:
NMLVSCROLL STRUCT
hdr NMHDR <>
_dx DWORD ?
dy DWORD ?
NMLVSCROLL ENDS
There is no other option: dx is a register, the lower half of edx :(
Effectively, the Microsoft Windows API is not compatible with the Microsoft Macro Assembler 8)
Fortunately, we simply got used to it :icon_mrgreen:
Hehe, fair enough.
It's probably too late now, but wouldn't it have been logical to prefix all members with _ and keep a standard across the whole library?
Quote from: Lonewolff on March 17, 2016, 10:58:53 AMwouldn't it have been logical to prefix all members with _ and keep a standard across the whole library?
It's really only a handful of cases. Having underscores all over the place would be very confusing.
Wouldn't uniform _'s across the whole API be less confusing than random occurances?
Things like 'width' are pretty common in structures.
To avoid those things i usually use a prefix for the struct mostly 1 character long.
for your Structure
LLDXGI_MODE_DESC STRUCT
Width DWORD 0
Height DWORD 0
LLDXGI_MODE_DESC ENDS
i would have used something like
LLDXGI_MODE_DESC STRUCT
mWidth DWORD 0
mHeight DWORD 0
LLDXGI_MODE_DESC ENDS[b]
(if there are other modes you could use an 'd' instead)
imo it also looks better.
But I've got a small question:
Why Init the Elements with 0? I thought it's more useful to create structs with unknown values ('?').
Or can i use the 0 (or any other value)as pre initialization?
Regards
Quote from: BolterVi on March 17, 2016, 10:38:53 PM
To avoid those things i usually use a prefix for the struct mostly 1 character long.
...
I thought it's more useful to create structs with unknown values ('?')
You can use whatever prefix you want for your own structures, but for
documented Windows API structures it is a really bad idea to modify them. Unless you are forced to because in the language of your choice
dx or
Width are reserved words.
Re unknown values:
dd ? is OK for most uses. Remember you do not allocate anything when you formulate a STRUCT. It is only when you write
myRc RECT <1, 2, 3, 4>
when memory gets reserved.