The MASM Forum

64 bit assembler => UASM Assembler Development => Topic started by: aw27 on October 12, 2017, 07:33:31 PM

Title: STRUCT variable initialization
Post by: aw27 on October 12, 2017, 07:33:31 PM
myst1 does not cause an error, myst2 cause an error.
In MASM both cause the error:  error A2177:nested structure improperly initialized


thest0 struct
v1 dword ?
thest0 ends

thest1A struct
vv1 dword ?
vv2 thest0 2 dup(<>)
thest1A ends

thest1B struct
vv2 thest0 2 dup(<>)
vv1 dword ?
thest1B ends

.data
myst1 thest1A <?>
myst2 thest1B <?>



Title: Re: STRUCT variable initialization
Post by: johnsa on October 12, 2017, 10:30:19 PM
I think this is sort of correct, in the case of myst1 the ? is applied to the dword and the nested struct has no initializers at all so is fine.
In the second case the in order initialisation requires a sub-structure of items to initialise the nested structure, which it doesn't have so fails.



myst1 thest1A <?> ;ok
myst2 thest1B <{<?>,<?>},?> ;ok
myst3 thest1B <?> ;fail



This is more feature than bug perhaps :)
Title: Re: STRUCT variable initialization
Post by: aw27 on October 12, 2017, 11:10:39 PM
I thing that not putting there the "?" is the correct way.  :icon_rolleyes:
myst1 thest1A <>
myst2 thest1B <>
Title: Re: STRUCT variable initialization
Post by: johnsa on October 12, 2017, 11:14:44 PM
yep that is also fine



myst4 thest1A <> ;ok
myst5 thest1B <> ;ok



no errors for that ?
Title: Re: STRUCT variable initialization
Post by: aw27 on October 12, 2017, 11:37:47 PM
Quote from: johnsa on October 12, 2017, 11:14:44 PM
yep that is also fine



myst4 thest1A <> ;ok
myst5 thest1B <> ;ok



no errors for that ?
Works fine for UASM and MASM
Title: Re: STRUCT variable initialization
Post by: xandaz on December 06, 2021, 06:44:53 PM
   Howdy. How does one initialize nested structures i know that there's a way similar to this which is in C but for masm32.TBBUTTON tbb[] =
{
   {0, IDM_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {1, IDM_FILE_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {2, IDM_FILE_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
   {3, IDM_FILE_PRINT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
   {4, IDM_EDIT_CUT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {5, IDM_EDIT_COPY,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {6, IDM_EDIT_PASTE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
   {7, IDM_HELP_ABOUT,TBSTATE_ENABLED,TBSTYLE_BUTTON ,0,0,0},
};

    Thanks for the help in advance
Title: Re: STRUCT variable initialization
Post by: fearless on December 06, 2021, 11:37:14 PM
.data

tbb1   \
       TBBUTTON <0, IDM_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0>
       TBBUTTON <1, IDM_FILE_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0>
       TBBUTTON <2, IDM_FILE_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0>
       TBBUTTON <0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0>
       TBBUTTON <3, IDM_FILE_PRINT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0>
       TBBUTTON <0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0>
       TBBUTTON <4, IDM_EDIT_CUT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0>
       TBBUTTON <5, IDM_EDIT_COPY,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0>
       TBBUTTON <6, IDM_EDIT_PASTE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0>
       TBBUTTON <0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0>
       TBBUTTON <7, IDM_HELP_ABOUT,TBSTATE_ENABLED,TBSTYLE_BUTTON ,0,0,0>
Title: Re: STRUCT variable initialization
Post by: xandaz on December 07, 2021, 05:54:00 AM
    Fearless! I can do that! i thought that there was some way of avoiding writing TBBUTTON in all those structures. But thanks. It's a valid effort.
Title: Re: STRUCT variable initialization
Post by: Greenhorn on December 07, 2021, 06:21:58 AM
You can also use this syntax:

tbb TBBUTTON   {0, IDM_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
         {1, IDM_FILE_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
         {2, IDM_FILE_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
         {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
         {3, IDM_FILE_PRINT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
         {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
         {4, IDM_EDIT_CUT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
         {5, IDM_EDIT_COPY,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
         {6, IDM_EDIT_PASTE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
         {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
         {7, IDM_HELP_ABOUT,TBSTATE_ENABLED,TBSTYLE_BUTTON ,0,0,0}


However, depending of the capabilities of your assembler it my happen that it is too large to fit in the assembler's line buffer.
If this is the case, you can prefix every line with the data type (in this case TBBUTTON) as HSE has posted.
Title: Re: STRUCT variable initialization
Post by: xandaz on December 11, 2021, 08:23:52 AM
    Thanks. That's what i was looking for.