P
Pietro Cerutti
Hi group,
is there any way in C to reference an expression in a variable?
I have a function matching the contents of a struct against a rule, and
I would like to pass the rule to be applied as an argument.
Assume the following structure:
typedef struct {
int field1;
int field2;
} structure;
and the following set of rules:
#define RULE1 (s->field1 = 1 && s->field2 = 2)
#define RULE2 (s->field1 = 2 && s->field2 = 3)
etc.
I would like to define the matching function as:
/*
* return 1 if s matches the rule, 0 otherwise
*/
int match(structure *s, <something_to_reference_a_rule>)
{
if(<something_to_reference_a_rule)
return (1);
else
return (0);
}
and the call the function as follows:
----8-->-------------------
structure s;
/* here s is filled somehow */
if(match(&s, RULE1))
/* rule 1 matches */
else if(match(&s, RULE2))
/* rule 2 matches */
----8-->-------------------
Any way to do something semantically equal to what explained above?
Thanks a lot!
is there any way in C to reference an expression in a variable?
I have a function matching the contents of a struct against a rule, and
I would like to pass the rule to be applied as an argument.
Assume the following structure:
typedef struct {
int field1;
int field2;
} structure;
and the following set of rules:
#define RULE1 (s->field1 = 1 && s->field2 = 2)
#define RULE2 (s->field1 = 2 && s->field2 = 3)
etc.
I would like to define the matching function as:
/*
* return 1 if s matches the rule, 0 otherwise
*/
int match(structure *s, <something_to_reference_a_rule>)
{
if(<something_to_reference_a_rule)
return (1);
else
return (0);
}
and the call the function as follows:
----8-->-------------------
structure s;
/* here s is filled somehow */
if(match(&s, RULE1))
/* rule 1 matches */
else if(match(&s, RULE2))
/* rule 2 matches */
----8-->-------------------
Any way to do something semantically equal to what explained above?
Thanks a lot!