Struct definition after static if

Simen kjaeraas simen.kjaras at gmail.com
Mon Dec 14 13:00:53 PST 2009


On Mon, 14 Dec 2009 15:43:49 +0100, Zarathustra  
<adam.chrapkowski at gmail.com> wrote:

> I must to put a 'struct definition' inside a 'static if block' but other  
> 'struct definition' doesn't see them.
>
> static if(_WIN32IE !< 0x0400)
> struct TVINSERTSTRUCT{
>
>   HTREEITEM hparent     ;
>   HTREEITEM hinsertafter;
>
>   union tagDUMMYUNIONNAME{
>     TVITEMEX itemex;
>     TVITEM item;
>   }
>
>   tagDUMMYUNIONNAME DUMMYUNIONNAME;
>  alias DUMMYUNIONNAME.itemex itemex;
>   alias DUMMYUNIONNAME.item   item  ;
>
> }
> else
> struct TVINSERTSTRUCT{
>   HTREEITEM hParent;
>   HTREEITEM hInsertAfter;
>   TVITEM item;
> }
>
> static if(_WIN32IE !< 0x0600)
> struct TVITEMEX{
>   UINT      mask         ;
>   HTREEITEM item         ;
>   UINT      state        ;
>   UINT      statemask    ;
>   TSTR      text         ;
>   UINT      textmax      ;
>   INT       image        ;
>   INT       selectedimage;
>   INT       children     ;
>   LPARAM    lparam       ;
>   INT       integral     ;
>   UINT      stateex      ;
>   HWND      hwnd         ;
>   INT       expandedimage;
> }
> else
> struct TVITEMEX{
>   UINT      mask         ;
>   HTREEITEM item         ;
>   UINT      state        ;
>   UINT      statemask    ;
>   TSTR      text         ;
>   UINT      textmax      ;
>   INT       image        ;
>   INT       selectedimage;
>   INT       children     ;
>   LPARAM    lparam       ;
>   INT       integral     ;
> }
>
> It works only if I declare TVITEMEX before TVINSERTSTRUCT.

Looks to me like a forward reference problem. Sadly, there
still are some of those in the language.


> And the second question, Is it possible to use anonymous unions
> and structs?

Yes. http://www.digitalmars.com/d/2.0/faq.html#anonymous


struct Foo
{
     union { int a; int b; }  // I HAZ NO NAYM
     struct { int c; int d; } // I HAZ NO NAYM
}

-- 
Simen


More information about the Digitalmars-d-learn mailing list