C
c.prog.fan
Hi
Please consider this code :
#define CONCAT(token,digit) token##digit
enum EN {
elem ;
} ;
struct ST {
int elem1;
int elem2;
} ;
void func (struct ST *st){
unsigned d;
for ( d=1 ; d <= 2 ; d++ )
if ( st->CONCAT(elem,d) == 0 )
st->CONCAT(elem,d) = 1;
return ;
} ;
As you may infer from the code the purpose is to change the value of
first 0-valued element of structure to 1.
I wonder if this could be done this way.Here compiler says elemd is
not a member of struct.I tried other things like st->CONCAT(elem,*&d)
but it did not work too.Also note that EN and ST can have several
members in same style but also note that ST can be a compound
structure.
Hints are appreciated on what to do here and also other methods to do
this in general.
ps. I assume this may work:
void func2 ( struct ST *st ){
unsigned d;
if ( st->elem1 == 0)
st->elem1=1;
else if ( st->elem2 == 0)
st->elem2 = 1;
else {} ;
return ;
};
Please consider this code :
#define CONCAT(token,digit) token##digit
enum EN {
elem ;
} ;
struct ST {
int elem1;
int elem2;
} ;
void func (struct ST *st){
unsigned d;
for ( d=1 ; d <= 2 ; d++ )
if ( st->CONCAT(elem,d) == 0 )
st->CONCAT(elem,d) = 1;
return ;
} ;
As you may infer from the code the purpose is to change the value of
first 0-valued element of structure to 1.
I wonder if this could be done this way.Here compiler says elemd is
not a member of struct.I tried other things like st->CONCAT(elem,*&d)
but it did not work too.Also note that EN and ST can have several
members in same style but also note that ST can be a compound
structure.
Hints are appreciated on what to do here and also other methods to do
this in general.
ps. I assume this may work:
void func2 ( struct ST *st ){
unsigned d;
if ( st->elem1 == 0)
st->elem1=1;
else if ( st->elem2 == 0)
st->elem2 = 1;
else {} ;
return ;
};