On 20 Jun, 10:29, onkar.n.maha... @gmail.com wrote:
no
C is statically compiled. By the time it executes everything
must be there and types are fixed. Dynamically linked libraries
can enable you to change functionality on the fly but the function
call interface remains fixed.
You really need a more dynamic language (Python, scheme etc)
or you can try and fake it (kludj it) in C. You really end
up writing an inferior version of scheme/lisp/python/forth.
Note that often Python etc. can often be called from C
(and vice versa).
About the best you can do is
if (strcmp (fun_name, "fred")
fred (a, b, c);
else
if (strcmp (fun_name, "joe")
joe(a, b);
if there are a lot of freds and joes maybe generate
the switch programitically . Perhaps from the
database.
--
Nick Keighley
Is it possible to from function call on fly in C programming
language ?
language ?
I am faced with an interesting problem in that I need to take function
name and arguments on fly (actually from Database as string ) and form
a function call based on that ?
>
something like FUN_NAME="fun1" , ARGS ="arg1,arg2,arg 3" , for this
pair function call must be
fun1(arg1,arg2, arg3);
>
assume that fun1(int,char,c har*) is defined before the call ?
>
i.e.,
>
get fun_name,args;
form a call
name and arguments on fly (actually from Database as string ) and form
a function call based on that ?
>
something like FUN_NAME="fun1" , ARGS ="arg1,arg2,arg 3" , for this
pair function call must be
fun1(arg1,arg2, arg3);
>
assume that fun1(int,char,c har*) is defined before the call ?
>
i.e.,
>
get fun_name,args;
form a call
must be there and types are fixed. Dynamically linked libraries
can enable you to change functionality on the fly but the function
call interface remains fixed.
You really need a more dynamic language (Python, scheme etc)
or you can try and fake it (kludj it) in C. You really end
up writing an inferior version of scheme/lisp/python/forth.
Note that often Python etc. can often be called from C
(and vice versa).
About the best you can do is
if (strcmp (fun_name, "fred")
fred (a, b, c);
else
if (strcmp (fun_name, "joe")
joe(a, b);
if there are a lot of freds and joes maybe generate
the switch programitically . Perhaps from the
database.
--
Nick Keighley
Comment