Author Topic: STRUCT variable initialization  (Read 4801 times)

aw27

  • Guest
STRUCT variable initialization
« 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

Code: [Select]
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

  • Member
  • ****
  • Posts: 893
    • Uasm
Re: STRUCT variable initialization
« Reply #1 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.

Code: [Select]

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


This is more feature than bug perhaps :)

aw27

  • Guest
Re: STRUCT variable initialization
« Reply #2 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 <>

johnsa

  • Member
  • ****
  • Posts: 893
    • Uasm
Re: STRUCT variable initialization
« Reply #3 on: October 12, 2017, 11:14:44 PM »
yep that is also fine

Code: [Select]

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


no errors for that ?

aw27

  • Guest
Re: STRUCT variable initialization
« Reply #4 on: October 12, 2017, 11:37:47 PM »
yep that is also fine

Code: [Select]

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


no errors for that ?
Works fine for UASM and MASM

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: STRUCT variable initialization
« Reply #5 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.
Code: [Select]
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

  • Member
  • ****
  • Posts: 577
    • Github
Re: STRUCT variable initialization
« Reply #6 on: December 06, 2021, 11:37:14 PM »
Code: [Select]
.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>
fearless

ASUS Crosshair 8 Hero, AMD 5950X, 32GB, MSI 5700XT, NZXT Kraken Z73, Seasonic 1000W PSU

Github Twitter Mastodon Gitbook

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: STRUCT variable initialization
« Reply #7 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.

Greenhorn

  • Member
  • ***
  • Posts: 488
Re: STRUCT variable initialization
« Reply #8 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.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: STRUCT variable initialization
« Reply #9 on: December 11, 2021, 08:23:52 AM »
    Thanks. That's what i was looking for.