The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: shashank_tulsyan on November 14, 2006, 02:36:28 PM

Title: typecast
Post by: shashank_tulsyan on November 14, 2006, 02:36:28 PM
I have a pointer to a masm structure.
How can I "typecast" it to it's original type and thus use it directly.
There may be no need of doing this :bg, but I want to know this just for knowlegde sake.

The struct:
xyz STRUCT
   version jint ?
   nOptions jint ?
   options DWORD ?
   ignoreUnrecognized jboolean ?   
xyz ENDS

LOCAL abc:DWORD ;say this is the pointer
LOCAL ste:xyz
   ;ste=(xyz)abc
Title: Re: typecast
Post by: u on November 14, 2006, 02:58:36 PM
local abc:ptr xyz

Utterly useless, save for readability....? A more readable line would be
local pSTE ; the address of "ste"
Title: Re: typecast
Post by: Tedd on November 14, 2006, 03:03:07 PM
There is no actual typecasting involved. And dwords can be considered untyped.
Anyway, what you do is 'type' the pointer when you have its value..


mov edi,ste
assume edi:PTR xyz    ;edi is now 'typed' to the xyz struct

mov eax,[edi].version
mov edx,[edi].options
...etc...

assume edi:nothing    ;turn the typing back off
Title: Re: typecast
Post by: shashank_tulsyan on November 14, 2006, 03:08:05 PM
Thanks I got it,
I had seen such an example a few days ago.
I don't write in masm generally, that's why I didn't recall it.