Does Function pointer make the program slow?

前端 未结 8 2599
你的背包
你的背包 2020-11-29 21:10

I read about function pointers in C. And everyone said that will make my program run slow. Is it true?

I made a program to check it. And I got the same results on bo

8条回答
  •  感动是毒
    2020-11-29 21:36

    Calling a function via a function pointer is somewhat slower than a static function call, since the former call includes an extra pointer dereferencing. But AFAIK this difference is negligible on most modern machines (except maybe some special platforms with very limited resources).

    Function pointers are used because they can make the program much simpler, cleaner and easier to maintain (when used properly, of course). This more than makes up for the possible very minor speed difference.

提交回复
热议问题