I don't believe there's any way to get the proprocessor to convert
a string literal to an identifier.
Even if there were, what would be the point? Why not just write:
int main(void) /* note proper declaration of main */
{
declare_func(abc);
declare_func(pqr);
}
Or, for that matter:
int main(void)
{
void abc(void);
void pqr(void);
}
And in fact, it rarely makes sense to declare a function inside
another function. (*Defining* a function inside another function
is illegal, unless you're using some compiler-specific extension).
Generally declarations for functions not defined in the current
source file should be in header files that you can #include:
#include "abc_pqr.h" /* declare abc and pqr */
int main(void)
{
/* ... */
}
Exactly what problem are you trying to solve?
--
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"
I have a function which takes a number of parameters. The parameter
names have a fixed template.
For e.g.
foo( int a, int b, int c)
I need to call foo() multiple times with the following arguments
foo( param_first, param_second, param_third);
foo( param1_first, param1_second, param1_third);
foo( test_first, test_second, test_third);
....
Lets assume the parameters are global variables.
I can have a table which lists all the parameters:
for e.g.
struct {
int first,
int second,
int third
} param_template
and then an array of this struct
[ {param_first, param_second, param_third},
{param1_first, param1_second, param1_third},
{test_first, test_second, test_third},
...
]
I can then iterate through this array and call foo().
I was thinking of having a array of strings and generating the
parameter names on the fly.
That is:
[ "param", "param1", "test"... ]
and then generate the parameter names on the fly and call foo()
I just realized this won't work.
A better approach would be to generate the static table.
#define GEN_TBL_ENTRY(x) { x##_first, x##_second, x##_third}
And then:
[ GEN_TBL_ENTRY(param),
GEN_TBL_ENTRY(param1),
GEN_TBL_ENTRY(test),
...
]
Thanks,
Parag