Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It depends on STL implementation. I means, the standard does not prevent to implement <code>std::array</code> using more members, or reserving more memory of that is really necessary (for example, for debugging), but I think is very improbable to found one <code>std::array</code> implementation without just use more of <code>T elem[N];</code> data member.</p> <p>If we assume the std::array implementation includes just one field for store the data and it allocate just the necessary memory (not more), <code>int v[100];</code> and where the data is stored in <code>array&lt;int, 100&gt; v;</code> will have the same layout, since from the standard:</p> <p>[array.overview 23.3.2.1 p1]:</p> <blockquote> <p>The elements of an array are stored contiguously, meaning that if <code>a</code> is an <code>array&lt;T, N&gt;</code> then it obeys the identity <code>&amp;a[n] == &amp;a[0] + n</code> for all <code>0 &lt;= n &lt; N</code>.</p> </blockquote> <p>and [class.mem 9.2 p20]:</p> <blockquote> <p>A pointer to a standard-layout struct object, suitably converted using a <code>reinterpret_cast</code>, points to its initial member (or if that member is a bit-field, then to the unit in which it resides) and vice versa. [ Note: There might therefore be unnamed padding within a standard-layout struct object, but not at its beginning, as necessary to achieve appropriate alignment. —end note ]</p> </blockquote> <p>Anyway, that depends on compiler and STL implementation. But the reversed code depends on compiler too. Why are you assuming int <code>a; int b[50];</code> will locate <code>a</code> and then array of <code>b</code> in memory in that order and not in the other if that declarations are not part of a <code>struct</code> or <code>class</code>? The compiler would decide other thing for performance reasons (but I see that is improbable). </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