All: I will be the first to admit that I have never been very good at developing macros so I was wondering if someone could assist me. What I would like to do is to take the following definition (from the NTDEF.H file) and make an equivalent macro:
an C example of it's use would be:
#define FIELD_OFFSET(type, field) ((LONG)&(((type *)0)->field))
#define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET (PCI_COMMON_CONFIG, DeviceSpecific))
Inside my copy of NTDEF.H, I have the following:
Well... if I understand what this is doing, the answer is kinda simple. Seems to me it's computing the distance into a stucture that an element resides. For example, if you had
// begin_winnt begin_ntminiport // Calculate the byte offset of a field in a structure of type type. #define FIELD_OFFSET(type, field) ((LONG)(INT_PTR)&(((type *)0)->field))
Then FIELD_OFFSET(MyStruct, B) would be 4. I'm basing this on the C cast of ZER0 to 'type', rather then a specific instance of 'type'. So....
MyStruct A DWORD 0 B DWORD 0 ENDS
That's the easy answer. What I don't like is it's CODE... this should be do-able completely as a macro (compile time thing) without any registers so you could say use the return value to load into ANY register (or memory) or your choice. Oh, and I didn't try actually compiling this, but I suspect there is at least one reserved keyword (if not two) in there ('field' and 'type' may need be renamed) Anyone else wanna try? :-) This message was edited by Ernie, on 5/2/2001 12:12:39 AM
FIELD_OFFSET MACRO type:REQ, field:REQ xor eax, eax lea .type.feild ENDM
Ernie: I greatly appreciate your assistance.