Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <ul> <li>Is there a big difference between "regular" code and inline code?</li> </ul> </blockquote> <p>Yes and no. No, because an inline function or method has exactly the same characteristics as a regular one, most important one being that they are both type safe. And yes, because the assembly code generated by the compiler will be different; with a regular function, each call will be translated into several steps: pushing parameters on the stack, making the jump to the function, popping the parameters, etc, whereas a call to an inline function will be replaced by its actual code, like a macro.</p> <blockquote> <ul> <li>Is inline code simply a "form" of macros?</li> </ul> </blockquote> <p><strong>No</strong>! A macro is simple text replacement, which can lead to severe errors. Consider the following code:</p> <pre><code>#define unsafe(i) ( (i) &gt;= 0 ? (i) : -(i) ) [...] unsafe(x++); // x is incremented twice! unsafe(f()); // f() is called twice! [...] </code></pre> <p>Using an inline function, you're sure that parameters will be evaluated before the function is actually performed. They will also be type checked, and eventually converted to match the formal parameters types.</p> <blockquote> <ul> <li>What kind of tradeoff must be done when choosing to inline your code?</li> </ul> </blockquote> <p>Normally, program execution should be faster when using inline functions, but with a bigger binary code. For more information, you should read <a href="http://www.gotw.ca/gotw/033.htm" rel="noreferrer" title="GoTW#33">GoTW#33</a>.</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