Does Function pointer make the program slow?

前端 未结 8 2596
你的背包
你的背包 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:41

    I think when people say this they're referring to the fact that using function pointers may prevent compiler optimizations (inlining) and processor optimizations (branch prediction). However, if function pointers are an effective way to accomplish something that you're trying to do, chances are that any other method of doing it would have the same drawbacks.

    And unless your function pointers are being used in tight loops in a performance critical application or on a very slow embedded system, chances are the difference is negligible anyway.

提交回复
热议问题