Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere are the function address literals in c++?
    text
    copied!<p><strong>UPDATE:</strong> After some additional reading, what I really wanted was guaranteed early binding (which should translated to an immediate call for non-virtual functions and non-PIC code), which can be done by passing a (member) function as a template parameter. The problem I had was that gcc &lt; 4.5 and icc 11.1 can generate some funky instructions for member function pointer template parameter calls. AFAICT, gcc >= 4,5 and vs2008 handle these template parameter calls fine.</p> <p>First of all, maybe <em>literals</em> is not the right term for this concept, but its the closest I could think of (not literals in the sense of functions as first class citizens).</p> <p>The idea is that when you make a conventional function call, it compiles to something like this:</p> <pre><code>callq &lt;immediate address&gt; </code></pre> <p>But if you make a function call using a function pointer, it compiles to something like this:</p> <pre><code>mov &lt;memory location&gt;,%rax callq *%rax </code></pre> <p>Which is all well and good. However, what if I'm writing a template library that requires a callback of some sort with a specified argument list and the user of the library is expected to know what function they want to call at <em>compile time</em>? Then I would like to write my template to accept a <strong>function literal as a template parameter.</strong> So, similar to </p> <pre><code>template &lt;int int_literal&gt; struct my_template {...};` </code></pre> <p>I'd like to write </p> <pre><code>template &lt;func_literal_t func_literal&gt; struct my_template {...}; </code></pre> <p>and have calls to func_literal within my_template compile to <code>callq &lt;immediate address&gt;</code>.</p> <p>Is there a facility in C++ for this, or a work around to achieve the same effect? If not, why not (e.g. some cataclysmic side effects)? How about C++0x or another language?</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