The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Mark_Larson on November 11, 2006, 02:47:59 PM

Title: nasm/yasm question
Post by: Mark_Larson on November 11, 2006, 02:47:59 PM
  can you declare a structure as a field inside your structure in  yasm/nasm?   I tried to get it to work and it keeps giving me an error message

struct  FRED
   asdf: resd 1
endstruc

struct MYOTHERSTRUC
  fredStruc: FRED
endstruc


Title: Re: nasm/yasm question
Post by: akane on November 11, 2006, 04:34:14 PM
In original nasm you cannot, but you can do a trick:
struct  FRED
.asdf  resd 1
endstruc

struct MYOTHERSTRUC
.fredStruc.asdf resd 1 ; inline FRED
.rcDraw.left   resd 1 ; inline RECT
.rcDraw.top    resd 1
.rcDraw.right  resd 1
.rcDraw.bottom resd 1
endstruc

Or, if you do not need to access FRED members - define it as space:
struct MYOTHERSTRUC
.fredStruc resb sizeof(FRED)
endstruc

where sizeof is defined as
%define sizeof(x) x %+ _size
just copy all FRED members and append "fredStruc." prefix to all. It could be done by extra macro that wraps the 'struct' macro, i didn't tried.