Does Function pointer make the program slow?

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

    Using a function pointer is slower that just calling a function as it is another layer of indirection. (The pointer needs to be dereferenced to get the memory address of the function). While it is slower, compared to everything else your program may do (Read a file, write to the console) it is negligible.

    If you need to use function pointers, use them because anything that tries to do the same thing but avoids using them will be slower and less maintainable that using function pointers.

提交回复
热议问题