I'm working on a program for numericaly solving differential equations, I have an index i which runs from -LATICE to LATICE. This index undergoes a coordinate substitution according to the problem and is mapped to [0, infinity) in radial coordinates, (-infinity,infinity) for one dimensional problems or [-N,N] for limited one-dimensional problems. I use a function pointer to choose which of the mapping function will be used during run-time.
The problem comes with the third mapping, the scaling [-N,N] is just i*N but N is also determined during run-time. So, is there a way of defining a function which is given as parameter N and returns a pointer to a function which multiplies i with N?
I tried a bit or round-working, I made a function with variable number of arguments, if more than one parameter is given, the second one sets a static variable N. The first parameter is just i and it returns i*N. And to make it compatible with the function pointer (which needs fixed number of arguments) it is called once to set N and then I use a function with just calls this one without second parameter. So, kind of ugly solution.
Anyone knows a solution to the actual problem?