Marcus
Marcus

Reputation: 5245

How to define a nested struct in MASM?

I'm trying to define a nested struct in MASM, but the errors are not very helpful, and I can't find any reference.

A simple example is the following:

        .const

child   struct
value   byte   ?
child   ends

parent  struct
Id      byte   ?
Child   child  {}
parent  ends

      .data

; ok
Parent1 parent {1}

; Error A2151: Missing operator in expression
; Error A2233: Invalid data initializer: Child
Parent2 parent {1, child {1}}

What do I need to corrent in Parent2's definition?

Upvotes: 2

Views: 335

Answers (1)

Michael
Michael

Reputation: 58457

The MASM 6.1 Programmer's Guide lists these syntax variants for defining variables of Structure or Union type:

[[name]] typename < [[initializer [[,initializer]]...]] >
[[name]] typename { [[initializer [[,initializer]]...]] }
[[name]] typename constant DUP ({ [[initializer [[,initializer]]...]] })

The initializers, if provided, should just be values corresponding in type to the field defined in the type declaration.

So to define a parent variable with an Id of 1 and a Child.value of 2, you could write:

Parent2 parent {1, {2}}

Upvotes: 3

Related Questions