digitalmars.D.learn - #define trouble
- dnewbie (29/29) Nov 26 2012 I have the following C struct from ldap.h
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (30/58) Nov 26 2012 A pair of @property functions would work, one of which may be unnecessar...
- dnewbie (2/68) Nov 27 2012 Perfect! Thank you.
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;
Nov 26 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
Nov 26 2012
On Tuesday, 27 November 2012 at 06:27:49 UTC, Ali Çehreli wrote:On 11/26/2012 10:05 PM, dnewbie wrote:Perfect! Thank you.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
Nov 27 2012








"dnewbie" <run3 myopera.com>