Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In this specific case, you'll find that g++ will tend to inline the accessor if you have any sort of optimization on. That right there is some minor code bloat, though it's debatable if the overhead of the call would be any less.</p> <p>However, one easy way to verify what's getting compiled is with the <code>nm</code> tool. If I compile your code with a simple <code>main()</code> to exercise <code>ArrayX::data()</code> and <code>ArrayY::data()</code> and then compile it with <code>-O0</code> to turn off inlining, I can run <code>nm -C</code> to see the symbols in the executable:</p> <pre><code>% nm -C test 0804a040 B ArrayX 0804a1e0 B ArrayY 08049f08 d _DYNAMIC 08049ff4 d _GLOBAL_OFFSET_TABLE_ 0804858c R _IO_stdin_used w _Jv_RegisterClasses 080484c4 W Array&lt;int, 100u&gt;::data() 08049ef8 d __CTOR_END__ 08049ef4 d __CTOR_LIST__ 08049f00 D __DTOR_END__ ... </code></pre> <p>You'll see that the <code>Array&lt;int, 100u&gt;::data()</code> symbol only occurs once in the final executable even though the object file for each of the two translation units contains it's own copy. (The <code>nm</code> tool also works on object files. You can use it to check that <code>x.o</code> and <code>y.o</code> each has a copy of <code>Array&lt;int, 100u&gt;::data()</code>.)</p> <p>If <code>nm</code> doesn't provide enough detail, you might also have a look at the <code>objdump</code> tool. It's a lot like <code>nm</code>, but with debugging symbols turned on, it can even show you things like a disassembly of the output executable with intermixed source lines.</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