c - I can change the pointer's function? -


in script languages, such perl , python, can change function in run-time. can in c changing pointer function?

something like:

void fun1() {     printf("fun1\n"); }  void fun2() {     printf("fun2\n"); }  int main() {     fun1 = &fun2;     fun1(); // print "fun2"     return 0; } 

no. can't that.

you can regard fun1 placeholder fixed entry point of function.

the semantic looking fun1=&fun2; point on every call fun1 causes fun2 called.

fun1 value not variable. in same way in statement int x=1; x variable , 1 value.

your code makes no more sense thinking 1=2; compile , point on x=x+1; result in x being incremented 2.

just because fun1 identifier doesn't mean it's variable let alone assignable.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -