Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Newer versions of GCC (4.4 and later) can inline and optimize a known function pointer using the option <code>-findirect-inlining</code>. This only works when GCC also knows all of the code that uses the pointer.</p> <p>For example, the C library function <code>qsort</code> will <em>not</em> benefit from this optimization. The compiled machine code for qsort is in the library, it expects a function pointer and the compiler cannot change that.</p> <p>However, if you had your own implementation of qsort and you placed it in a header file or you used the very new GCC link-time optimization features, then GCC <em>would</em> be able to take your calling code, the function pointed to, and your qsort source and compile it all together, optimized for your data types and your comparison function.</p> <p>Now, the only times that this really matters is when the function call overhead is much larger than the function itself. In your example of a function that does nothing much, using a function pointer is serious overhead. In my example of a qsort comparison, the function pointer call is also quite expensive. But in some other application like Windows event dispatch, it hardly matters.</p> <p>Since you are using C++ you should study templates. A template function can accept a so-called <code>function object</code> which is just an object that implements <code>operator()</code> <em>and</em> it can accept function pointers. Passing a function object will allow the C++ compiler to inline and optimize almost all of the code involved.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload