Poniendo bucle dentro de macro C
Estoy buscando una manera de convertir la siguiente estructura de función a una macro. Lo sé, es un ejemplo tonto e inútil, pero ilustra el punto ya que no puedo dar mi código fuente real.
int foo(int x, int y)
{
do
{
--x;
++y;
}while(x > y);
return x * y; //note that x and y have changed values here.
}
Para poder llamar a la función en main o alguna otra función como esta:
int next_x = foo(x,y);
Parece que no puedo obtener la sintaxis correcta al 100% aquí. Este es mi pobre intento:
#define FOO(x,y) \
( \
do \
{ \
--x; \
++y; \
}while(x < y), \
x \
)
El razonamiento de lax Al final es para que, en teoría, pueda hacer esto.
int next_x = FOO(x,y);
pero en cambio, me sale un error de sintaxis y no estoy seguro de por qué. Cualquier ayuda sería apreciada.
================================================
Información adicionalTambién debo señalar que tengo otras macros que están estructuradas en consecuencia:
#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 \
)
Y así, puedo y he hecho lo siguiente:
float my_flt = NEXT_FLOAT(x,y,temp);