flat assembler
Message board for the users of flat assembler.

Index > Main > unions and named substructures

Author
Thread Post new topic Reply to topic
Expcn



Joined: 10 Apr 2006
Posts: 4
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
Post 10 Apr 2006, 15:29
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
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 Smile
Post 10 Apr 2006, 15:52
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Expcn



Joined: 10 Apr 2006
Posts: 4
Expcn 10 Apr 2006, 19:54
How i do this:
Code:
;file1.inc
struct TAIL 
  field_1 dw ?
  field_2 dd ?
  field_3 dd ?
ends

struct BAR
 field_1 dd ?
 struct TAIL
  field_2 dd ?
  field_2b db ?
 ends
ends
    
Post 10 Apr 2006, 19:54
View user's profile Send private message Reply with quote
Kermil



Joined: 26 Oct 2005
Posts: 35
Location: Russia
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
    
Post 11 Apr 2006, 07:04
View user's profile Send private message ICQ Number Reply with quote
Expcn



Joined: 10 Apr 2006
Posts: 4
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]
    
Post 11 Apr 2006, 15:38
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
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]    

?
Post 11 Apr 2006, 16:09
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
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
Post 11 Apr 2006, 16:58
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
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".
Post 11 Apr 2006, 17:25
View user's profile Send private message Visit poster's website Reply with quote
Expcn



Joined: 10 Apr 2006
Posts: 4
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.
Post 13 Apr 2006, 15:14
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.