how to create masm32 struct with negativ member?
samplestruc struct
s1 dd ?
s2 dd ?
s3 dd ?
samplestruct ends
I want:
s1 offset -4
s2 offset 0
s3 offset 4
mov eax, = mov eax,
possible?
samplestruc struct
s1 dd ?
s2 dd ?
s3 dd ?
samplestruct ends
I want:
s1 offset -4
s2 offset 0
s3 offset 4
mov eax, = mov eax,
possible?
That would defeat the purpose and design of a structure.
It would be easier to help you if you gave us a practical example/application of this desired method :)
It would be easier to help you if you gave us a practical example/application of this desired method :)
SpooK: returning pointer to data to caller, with some (private) info stored in same block, at minus offset. For example alloc can save size of block, at -4. Or current string length and buffer size can be saved at -4, -8. etc. etc.
SpooK: returning pointer to data to caller, with some (private) info stored in same block, at minus offset. For example alloc can save size of block, at -4. Or current string length and buffer size can be saved at -4, -8. etc. etc.
That is still apart of the structure as it must be from allocated memory.
There is no need to conceptualize a "negative offset", as I said, it defeats the purpose. Structures should be designed with intent. Structures start at zero. If you want to abstract a "negative offset", simply pass a pointer to STRUCT + X bytes (STRUCT.label_of_offset) instead of just STRUCT. Nested structures also work equally as well... windows.inc is full of them.
I guess what I am trying to say is keep it simple, there is no need for unnecessary abstractions. Stay consistent... otherwise prepare to suffer the wrath of memory/data corruption and hard-to-trace bugs ;)
There is no need to conceptualize a "negative offset", as I said, it defeats the purpose.
which purpose exactly? Let's take alloc as example. Purpose of alloc is to return pointer to block of memory. it needs to save some data, before the block (at negative offset).
When user passes pointer to such block to another memory management function, it knows that there is structure before the block. That is, at pointer-4, pointer-8 etc.
Which one do you find to be nicer?
mov ecx,
mov edx,
or this?
mov ecx,
mov edx,
Structures start at zero
it is pretty common to work with structure pointers which do not point to beginning of structure, but into middle or behind them.
Of course sometimes it's better to subtract size of "negative part of structure" from pointer, and use usual way. But sometimes there is no point to do that.
Posted on 2007-02-21 04:07:10 by vid