#define trouble

Ali Çehreli acehreli at yahoo.com
Mon Nov 26 22:27:49 PST 2012


On 11/26/2012 10:05 PM, dnewbie wrote:
> I have the following C struct from ldap.h
>
> typedef struct ldapmod {
> int mod_op;
> char *mod_type;
> union mod_vals_u {
> char **modv_strvals;
> struct berval **modv_bvals;
> } mod_vals;
> #define mod_values mod_vals.modv_strvals
> #define mod_bvalues mod_vals.modv_bvals
> } LDAPMod;
>
> It is used like this:
> LDAPMod title;
> title.mod_values = x;
>
> I wonder how can I write the line 'title.mod_values = x;' in D.
> Currently I do like this:
>
> struct ldapmod {
> int mod_op;
> char* mod_type;
> union mod_vals_u {
> char** modv_strvals;
> berval** modv_bvals;
> }
> mod_vals_u mod_vals;
> }
> alias ldapmod LDAPMod;
>
> LDAPMod title;
> title.mod_vals.modv_strvals = x;
>
>

A pair of @property functions would work, one of which may be unnecessary:

alias int berval;

struct ldapmod {
     int    mod_op;
     char* mod_type;
     union mod_vals_u {
         char**  modv_strvals;
         berval** modv_bvals;
     }
     mod_vals_u mod_vals;

     char** mod_values() @property
     {
         return mod_vals.modv_strvals;
     }

     void mod_values(char** value) @property
     {
         mod_vals.modv_strvals = value;
     }

     // similarly for mod_bvalues...
}
alias ldapmod LDAPMod;

void main()
{
     LDAPMod title;
     char** x;
     // title.mod_vals.modv_strvals = x;
     title.mod_values = x;
}


Ali


More information about the Digitalmars-d-learn mailing list