### Author Topic: Dumb question: how to declare a nested structure?  (Read 8069 times)

#### dedndave

• Member
• Posts: 8825
• Still using Abacus 2.0
##### Re: Dumb question: how to declare a nested structure?
« Reply #15 on: April 24, 2015, 02:18:51 AM »

http://masmforum.com/board/index.php?topic=1700.msg17265#msg17265

#### jj2007

• Member
• Posts: 10260
• Assembler is fun ;-)
##### Re: Dumb question: how to declare a nested structure?
« Reply #16 on: April 24, 2015, 02:18:59 AM »
Yeah, we have aliens here, and they use time machines, too 8)
http://www.masmforum.com/board/index.php?topic=1700.0

#### nidud

• Member
• Posts: 1923
##### Re: Dumb question: how to declare a nested structure?
« Reply #17 on: April 24, 2015, 03:48:58 AM »
Well, it is a MASM bug, but the size issue may be solved by the dummy struct

Seems a bit easier to use the LABEL compare to all these macros thought.

#### MichaelW

• Global Moderator
• Member
• Posts: 1209
##### Re: Dumb question: how to declare a nested structure?
« Reply #18 on: April 24, 2015, 11:04:13 AM »
It does look like another MASM bug. At least for ML 6.14 and 6.15 DUP works as expected when it's embedded in the structure declaration.
Code: [Select]
`;===============================================================================include \masm32\include\masm32rt.inc;===============================================================================S1 STRUCT    x DWORD ?    y DWORD ?S1 ENDSS2 STRUCT    s1 S1 2 dup(<>)S2 ENDSS3 STRUCT    s2 S2 16 dup(<>)S3 ENDS;===============================================================================.data    s3 S3 <>.code    ;===============================================================================  start:;===============================================================================    printf("%d\n\n",sizeof S3)        mov   esi, alloc(sizeof S3)        mov   [esi].S3.s2.s1.x, 1    mov   [esi].S3.s2.s1[8].x, 2       mov   [esi].S3.s2[32].s1.y, 3    push  [esi].S3.s2.s1.x    pop   s3.s2.s1.x    push  [esi].S3.s2.s1[8].x       pop   s3.s2.s1[8].x       push  [esi].S3.s2[32].s1.y    pop   s3.s2[32].s1.y           printf("%d\n",s3.s2.s1.x)    printf("%d\n",s3.s2.s1[8].x)    printf("%d\n\n",s3.s2[32].s1.y)    free  esi     inkey    exitend start;===============================================================================`
Code: [Select]
`00401021 C70601000000           mov     dword ptr [esi],100401027 C7460802000000         mov     dword ptr [esi+8],20040102E C7462403000000         mov     dword ptr [esi+24h],300401035 FF36                   push    dword ptr [esi]00401037 8F0500304000           pop     [off_00403000]0040103D FF7608                 push    dword ptr [esi+8]00401040 8F0508304000           pop     [off_00403008]00401046 FF7624                 push    dword ptr [esi+24h]00401049 8F0524304000           pop     [off_00403024]`

Well Microsoft, here’s another nice mess you’ve gotten us into.

#### NoCforMe

• Member
• Posts: 89
##### Re: Dumb question: how to declare a nested structure?
« Reply #19 on: April 24, 2015, 12:01:38 PM »
you're right, it should be simple - lol

but, the work-around seems simple enough
i would guess you're going to be addressing with a register, anyways

[insert code example here]

at the end of the day, it's an array of 4-dword elements   :P

tomorrow, i'll see if i can figure out the syntax issue

Thanks. I'm going to go this route for now, as it's nice and simple (just have to remember to bunch the array elements in groups of 8 ). Yes, using a register to index them.

If someone figures out how to make MASM do this, cool. Will keep checking back here.

#### dedndave

• Member
• Posts: 8825
• Still using Abacus 2.0
##### Re: Dumb question: how to declare a nested structure?
« Reply #20 on: April 24, 2015, 12:32:55 PM »
Michael's solution in reply #18 looks like it has wheels   :t

i'd call that as near as it gets

Code: [Select]
`\$maxActiveItems EQU 16\$mhStruct STRUCT  _handle HWND ?  _flags DD ?  _X DD ?  _Y DD ?\$mhStruct ENDS\$moveHandleStruct STRUCT  _mh \$mhStruct 8 DUP(<>)\$moveHandleStruct ENDS\$HandleArray STRUCT  \$moveHandleStruct \$maxActiveItems DUP(<>)\$HandleArray ENDS    .DATA?MoveHandles \$HandleArray <>`
i say Michael's - i guess it's an implementation of qWord's method that i linked earlier

#### MichaelW

• Global Moderator
• Member
• Posts: 1209
##### Re: Dumb question: how to declare a nested structure?
« Reply #21 on: April 24, 2015, 01:20:35 PM »
i say Michael's - i guess it's an implementation of qWord's method that i linked earlier

I did mine at home where I don't currently have a working Internet connection (due to a hardware failure), and while I did not recall qWord's post, that could well be where the idea came from.
Well Microsoft, here’s another nice mess you’ve gotten us into.