I'm looking for a way to convert the following function structure to a macro. I know, it's a silly and pointless example, but it illustrates the point since I cannot give out my actual source code.
int foo(int x, int y)
{
do
{
--x;
++y;
}while(x > y);
return x * y; //note that x and y have changed values here.
}
So that I can call the function in main or some other function like so:
int next_x = foo(x,y);
I cannot seem to get the syntax 100% correct here. This is my poor attempt:
#define FOO(x,y) \
( \
do \
{ \
--x; \
++y; \
}while(x < y), \
x \
)
The reasoning for the x at the end is so that I could, in theory, be able to do this
int next_x = FOO(x,y);
but instead, I get a syntax error and I'm not sure why. Any help would be appreciated.
===============================================
Additional Info
I should also note that I have other macros which are structured accordingly:
#define INIT(x,y)
(
x = //something,
y = //something
)
#define NEXT_INT(x,y) \
( \
INIT(x,y), \
get_next_num(x,y) \ //Note, this is an inline function call , not a macro.
)
#define NEXT_FLOAT(x,y,temp) \
( \
temp = NEXT_INT(x,y), \
temp ? temp * 1.23456 : FLT_MIN \
)
And so, I can and have done the following:
float my_flt = NEXT_FLOAT(x,y,temp);