You got it perfect. Problem is absolutely like that. Just we need to
add some more complexity in the sense that I have to write 1000 of
such functions.
some of them may be using 400 local variables, some 4 only. I want all
such functions to have their own local variables, due to performance
issue. (I am not touching a[0] Vs a0 issue here but i will certainly
look into that.) And so as suggested by someone that write all
variables in one file and include that in one function was not very
attractive to me because the function that uses only 4 variables will
give only 396 warning.
So, to refine the description a bit, you want to do the following:
Repeat 1000 times:
Generate code.
Based on what you learned while generating the code, generate
variable declarations (4 to 400 of them).
Put the declarations and the code (in that order!) into a
function definition.
So the end result is going to be a (really big!) C source file
containing 1000 function definitions.
(You *could* put each function definition in its own separate source
file, compiling each one individually and linking them all together
into your final program. I don't know enough about your underlying
problem to know whether this would be a better approach. It should
work either way.)
Yes it will work and i din;t think about it earlier. But only issue
i see here is when writing 1000 functions in the same file I will
have to repeat ( 1. create temp file 2. add declaration in a.c
3. append temp to a.c ) 1000 times.
Yes, and why is this a problem? This is exactly the kind of tedious
work that computers are good at. (If you use temp files, don't forget
to clean them up.) Or, as I suggested, you might be able to store the
code in memory rather than writing it to a temporary file. That might
speed things up substantially. Do whichever is more convenient.
Yes declaration need not to have an order. They just have to be before
their use. I am saving that data on a graph but this data is also
being populated on the fly when I am generating the code. so even an
extra traversal before generating the code will not work.
Sorry, I didn't quite follow that.
Possibly true. In fact solution through array and repeated
concatenation are welcome pointers for me.
And I still have no idea what your underlying problem is. You're
assuming a particular solution, but if we knew the problem we might be
able to suggest a completely different approach. (Or not.)
One vague thought: You're writing 1000 functions, with up to hundreds
of variables in each. This whole thing is presumably a representation
of something in your problem space. Would it make more sense to
represent it all as data rather than code? Again, without knowing
what problem you're trying to solve, I can't be more specific.
--
Keith Thompson (The_Other_Keith) (e-mail address removed) <
http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"