Multiple copies of same function in C
I wrote a code meant to make some very fast calculations. I assume I know
a certain number (because I can safely assume it is <15 and >2. Not a
pretty way to implement something, but it allows loop unrolling and makes
the code much faster)
(The code was written this way for practical considerations. I know it's
not a good way to write a code, but in this case, that's the way it has to
be)
Problem is I need to change the number in #define and compile again and
again for every value (Using Visual C++ 2010)
I figured macros might be the way to go, but I couldn't find out how to do
such a thing. my lame attempt filed:
#define myCustomFunc(number) void myF_number() \
{ printf("%d",number); \
}
my goal is that something like this:
create_myfunc(2);
create_myfunc(3);
create_myfunc(4);
will expand to:
void myFunc_2(...)
{ ... #pragma unroll
for (int i<0; i<2;i++)
...
}
void myFunc_3(...)
{ ... #pragma unroll
for (int i<0; i<3;i++)
...
}
etc. and to be able to call these functions from some function by their
name, including the constant in it
if (x==2)
myFunc_2();
But from what I understand, one of the problems with doing such a thing is
that such code doesn't expand if it's not inside a function, just gives an
error.
No comments:
Post a Comment