A
Ann O'Nymous
I have a C function macro defined something like this:
void f1(int *, int);
void f2(int *, int);
....
#define FOO(i,j)\
{ int k[10];\
f1(k,i);\
f2(k,j);\
}
....
and calls like FOO(123,456); work fine.
Now I want to change f2 to return an int, and change FOO to return that int.
int xyz;
....
xyz = FOO(123,456);
The preprocessor would expand that as follows:
xyz = { int k[10];
f1(k,123);
f2(k,456);
}
Is it possible to rework FOO so it does the equivalent of this:
{ int k[10];
f1(k,123);
xyz = f2(k,456);
}
I can do it with a hidden variable in FOO:
....
l = f2(k,j);
and calling it like this:
FOO(123,456);
xyz = l;
which is poor style, someday some poor sap will wonder where "l" came from.
I could also add a third parameter for the output value.
#define FOO(i,j,l)\
....
l = f2(k,j);
and the call would be:
FOO(123,456,xyz);
Is there a better way? I want to use the xyz=FOO(123,456) form.
void f1(int *, int);
void f2(int *, int);
....
#define FOO(i,j)\
{ int k[10];\
f1(k,i);\
f2(k,j);\
}
....
and calls like FOO(123,456); work fine.
Now I want to change f2 to return an int, and change FOO to return that int.
int xyz;
....
xyz = FOO(123,456);
The preprocessor would expand that as follows:
xyz = { int k[10];
f1(k,123);
f2(k,456);
}
Is it possible to rework FOO so it does the equivalent of this:
{ int k[10];
f1(k,123);
xyz = f2(k,456);
}
I can do it with a hidden variable in FOO:
....
l = f2(k,j);
and calling it like this:
FOO(123,456);
xyz = l;
which is poor style, someday some poor sap will wonder where "l" came from.
I could also add a third parameter for the output value.
#define FOO(i,j,l)\
....
l = f2(k,j);
and the call would be:
FOO(123,456,xyz);
Is there a better way? I want to use the xyz=FOO(123,456) form.