www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Binding Nested C Structs

reply "Craig Dillabaugh" <craig.dillabaugh gmail.com> writes:
I am trying to bind to a C union with a number of nested structs 
declared as follows:

typedef union {
     int         Integer;

     struct {
         int     nCount;
         int     *paList;
     } IntegerList;

     struct {
         int     nCount;
         GIntBig *paList;
     } Integer64List;

} OGRField;

According to http://wiki.dlang.org/D_binding_for_C#Nested_Structs
I should attempt to write something like (last example shown):

extern(C) union OGRField
{
    int Integer;
    struct {
       int  nCount;
       int* paList;
    }

    struct {
       int      nCount;
       GIntBig* paList;
    }
}

But that is obviously not going to work.  Does anyone know the 
right way
to handle nested C structs of that form.
Jul 09 2015
next sibling parent "Craig Dillabaugh" <craig.dillabaugh gmail.com> writes:
On Friday, 10 July 2015 at 03:38:49 UTC, Craig Dillabaugh wrote:
 I am trying to bind to a C union with a number of nested 
 structs declared as follows:

 typedef union {
     int         Integer;

     struct {
         int     nCount;
         int     *paList;
     } IntegerList;

     struct {
         int     nCount;
         GIntBig *paList;
     } Integer64List;

 } OGRField;

 According to 
 http://wiki.dlang.org/D_binding_for_C#Nested_Structs
 I should attempt to write something like (last example shown):

 extern(C) union OGRField
 {
    int Integer;
    struct {
       int  nCount;
       int* paList;
    }

    struct {
       int      nCount;
       GIntBig* paList;
    }
 }

 But that is obviously not going to work.  Does anyone know the 
 right way
 to handle nested C structs of that form.
OK Found the answer elsewhere on the same page: extern(C) union OGRField { int Integer; struct _IntegerList { int nCount; int* paList; } _IntegerList IntegerList; struct _Integer64List { int nCount; GIntBig* paList; } _Integer64List Integer64List; }
Jul 09 2015
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2015-07-10 05:38, Craig Dillabaugh wrote:
 I am trying to bind to a C union with a number of nested structs
 declared as follows:

 typedef union {
      int         Integer;

      struct {
          int     nCount;
          int     *paList;
      } IntegerList;

      struct {
          int     nCount;
          GIntBig *paList;
      } Integer64List;

 } OGRField;

 According to http://wiki.dlang.org/D_binding_for_C#Nested_Structs
 I should attempt to write something like (last example shown):

 extern(C) union OGRField
 {
     int Integer;
     struct {
        int  nCount;
        int* paList;
     }

     struct {
        int      nCount;
        GIntBig* paList;
     }
 }

 But that is obviously not going to work.  Does anyone know the right way
 to handle nested C structs of that form.
I think it will work but the API would be different. -- /Jacob Carlborg
Jul 10 2015