News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

STRUCT variable initialization

Started by aw27, October 12, 2017, 07:33:31 PM

Previous topic - Next topic

aw27

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 <?>




johnsa

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 :)

aw27

I thing that not putting there the "?" is the correct way.  :icon_rolleyes:
myst1 thest1A <>
myst2 thest1B <>

johnsa

yep that is also fine



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



no errors for that ?

aw27

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

xandaz

   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

fearless

.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>

xandaz

    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.

Greenhorn

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.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

    Thanks. That's what i was looking for.