News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Problem pre-initializing union inside structure with JWASM

Started by peter_asm, February 26, 2014, 12:27:58 PM

Previous topic - Next topic

peter_asm

I've tried a few ways to do this with JWASM and it complains of too many values.
Essentially I want to pre-initialize a sockaddr_in structure.


IN_ADDR struct
  union S_un
    struct S_un_b
      s_b1 u_char ?
      s_b2 u_char ?
      s_b3 u_char ?
      s_b4 u_char ?
    ends
  struct S_un_w
    s_w1 u_short ?
    s_w2 u_short ?
  ends
    S_addr u_long ?
  ends
IN_ADDR ends

PIN_ADDR typedef ptr IN_ADDR
LPIN_ADDR typedef ptr IN_ADDR

sockaddr_in struct
  sin_family SWORD ?
  sin_port   WORD ?
  sin_addr   IN_ADDR <>
  sin_zero   SBYTE 8 dup (?)
sockaddr_in ends


With IP address 0100007Fh and port 80, AF_INET I try initialize to this

local_address sockaddr_in <AF_INET, 80, <0100007Fh>, 0>

JWASM complains:

Initializer must be a string or single item: S_un
Too many initial values for structure: 0100007Fh
Initializer must be a string or single item: 0


and this

local_address sockaddr_in <AF_INET, 80, <01h,00h,00h,7Fh>, 0>



qWord

local_address sockaddr_in <AF_INET, 80, <<<01h,00h,00h,7Fh>>>,<0>>
Remarks that for unions only the first member can be initialized (in this case:  S_un_b).
MREAL macros - when you need floating point arithmetic while assembling!