flat assembler
Message board for the users of flat assembler.
Index
> Main > unions and named substructures |
Author |
|
Expcn 10 Apr 2006, 15:29
How to define unions and named substructures?
struct BAR field_1 dd ? struct TAIL field_2 dd ? field_2b db ? ends ends |
|||
10 Apr 2006, 15:29 |
|
Madis731 10 Apr 2006, 15:52
like:
Code: struct TAIL field_2 dd ? field_2b db ? ends struct BAR field_1 dd ? tail TAIL ends Or you need something fancier |
|||
10 Apr 2006, 15:52 |
|
Kermil 11 Apr 2006, 07:04
Look the following example:
Code: struct BAR field_1 dd ? field_2 dd ? ends bar BAR mov esi, bar mov eax, [esi + BAR.field_2] ; get field_2 movzx eax, byte [esi + BAR.field_2] ; get field_2b |
|||
11 Apr 2006, 07:04 |
|
Expcn 11 Apr 2006, 15:38
You not understand my questions, look this:
how to define structure BAR, without extern definition structure tail, that is structure tail must be valid only within structure BAR, to avoid conflicts with others same names, because substructures that has name tail, can be present in others structures, but with different fields Code: struct BAR field_1 dd ? struct tail field_2 dd ? field_2b db ? ends ends struct BAR2 field_a dd ? field_b dd ? struct tail field_5 dd ? field_6 dd ? field_7 dw ? field_8 db ? ends ends bar BAR bar2 BAR2 mov eax,[bar.tail.field_2] mov cx,[bar2.tail.field_7] |
|||
11 Apr 2006, 15:38 |
|
Tomasz Grysztar 11 Apr 2006, 16:09
Isn't it just:
Code: struct __tmp1 field_2 dd ? field_2b db ? ends struct BAR field_1 dd ? tail __tmp1 ends struct __tmp2 field_5 dd ? field_6 dd ? field_7 dw ? field_8 db ? ends struct BAR2 field_a dd ? field_b dd ? tail __tmp2 ends bar BAR bar2 BAR2 mov eax,[bar.tail.field_2] mov cx,[bar2.tail.field_7] ? |
|||
11 Apr 2006, 16:09 |
|
RedGhost 11 Apr 2006, 16:58
he wan'ts to define a union or 'substructure' which can only be accessed from within the structure e.g.
Code: struct BAR union TAIL endu ends abc TAIL ;ERROR: TAIL is only valid within BAR unless redefined as an external version he wants this so BAR.TAIL.a is not the same as BAR2.TAIL.a when the union TAIL in BAR2 is different than that of BAR |
|||
11 Apr 2006, 16:58 |
|
Tomasz Grysztar 11 Apr 2006, 17:25
But the name of substructure, which is in fact an instance is not the same as the name of the structure, which is just a type. As in my example, you can define type named "__tmp1" and then define the instance of "__tmp1" structure, named "TAIL" - this does not imply that you have a type named "TAIL".
|
|||
11 Apr 2006, 17:25 |
|
Expcn 13 Apr 2006, 15:14
Tomasz Grysztar, its right! but little problem still exist, that is bad code readability, because with such structure definitions, i can't see substructures fields in structures where its declared, i'm must find definitions outside structures.
|
|||
13 Apr 2006, 15:14 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.