Thread: Eval() in C?
View Single Post
  #3   Spotlight this post!  
Unread 06-01-2008, 23:33
mluckham's Avatar
mluckham mluckham is offline
Registered User
FRC #0758 (Sky Robotics)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Ontario, Canada
Posts: 116
mluckham will become famous soon enoughmluckham will become famous soon enough
Re: Eval() in C?

There is nothing like that (converting a string to a function address).

To simulate it, you would compare a variable (perhaps a string variable containing the name of your function) to some constant, then use a switch() statement to call the appropriate function. Example:

int foo( int a, int b)
{
return a + b;
}

int bar( int a, int b)
{
return a - b;
}


main()
{
char funcname[] = "foo";

...

switch (funcname)
{
case "foo":
foo(a,b);
case "bar":
bar(a,b);
}

...

}
}