Thread overview
Struct definition after static if
Dec 14, 2009
Zarathustra
Dec 14, 2009
Don
Dec 14, 2009
Zarathustra
Dec 14, 2009
bearophile
Dec 14, 2009
Simen kjaeraas
Dec 14, 2009
Zarathustra
Dec 14, 2009
Simen kjaeraas
December 14, 2009
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. And the second question, Is it possible to use anonymous unions and structs?
December 14, 2009
Zarathustra 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. And the second question, Is it possible to use anonymous unions and structs?

Does that compile???   It shouldn't. !< is a floating-point operator.
December 14, 2009
Don Wrote:

> Does that compile???   It shouldn't. !< is a floating-point operator.


Of course that compile (thanks Got DMD behaviors logically). In this case !< mean nothing less >= NOT GREATER THAN is semantically same as GREATER OR EQUAL.

Yes, you're right !< is a floationg-point operator but it doesn't matter.

The problem is:
struct B{
  A a;
}

struct A{
}

works ok, but
struct B{
  A a;
}

static if(TRUE) struct A{
}

causes:
  Error: identifier 'A' is not defined
  Error: A is used as a type
  Error: variable B.a voids have no value

December 14, 2009
Matthew:

A cleaned up case:

struct B { A a; }

static if(true)
  struct A {}

void main() {}

I think this may be a forward reference bug.

Bye,
bearophile
December 14, 2009
On Mon, 14 Dec 2009 15:43:49 +0100, Zarathustra <adam.chrapkowski@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
December 14, 2009
Simen kjaeraas Wrote:

> Looks to me like a forward reference problem. Sadly, there still are some of those in the language.
> 
> 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

Thanks Simen. I hoped D will be bugless and static if will be possible inside enums.

Best regards

December 14, 2009
Zarathustra <adam.chrapkowski@gmail.com> wrote:

> Thanks Simen. I hoped D will be bugless and static if will be possible inside enums.

Static if will probably never be usable inside enums. The best way to
get something like it - at least currently - is to use string mixins
and/or the defineEnum template in std.typecons.

-- 
Simen