Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy the memory allocation like this when the const reference release to a different type in g++4.7.3
    primarykey
    data
    text
    <p>My compiler is g++ 4.7.3</p> <pre><code>long i = 2222; const long&amp; lref = i; const int&amp; iref = i; printf("i=%p lref=%p iref=%p \n", &amp;i , &amp;lref, &amp;iref); </code></pre> <p>The result is </p> <pre><code>i=0xbfd78760 lref=0xbfd78760 iref=0xbfd78764 </code></pre> <p>Why the address of <code>iref</code> is higher than <code>i</code></p> <p>I think it may just like this: when <code>const int&amp;</code> reference to <code>long</code>, it like </p> <pre><code>int temp = i const int&amp; iref = temp; </code></pre> <p>==========================================================</p> <p>CODE2</p> <p>However when the code like </p> <pre><code>long i = 2222; const long&amp; lref = i; const int&amp; iref = i; int a = 10; int b = 10; printf("i=%p lref=%p iref=%p a=%p b=%p\n", &amp;i , &amp;lref, &amp;iref, &amp;a, &amp;b); </code></pre> <p>The result is </p> <pre><code>i=0xbfade768 lref=0xbfade768 iref=0xbfade774 a=0xbfade76c b=0xbfade770 </code></pre> <p>Why the address of <code>a</code> and <code>b</code> is lower than <code>iref</code> in the stack?</p> <p>==========================================================</p> <p>CODE3</p> <p>When the code like </p> <pre><code>long i = 2222; const long&amp; lref = i; const int&amp; iref = i; printf("i=%p lref=%p iref=%p \n", &amp;i , &amp;lref, &amp;iref); </code></pre> <p>The result is </p> <pre><code>i=0xbfbe3f84 lref=0xbfbe3f84 iref=0xbfbe3f83 </code></pre> <p>When the type of <code>iref</code> is <code>char</code>,why the address of <code>iref</code> is lower than <code>i</code>?</p> <p>Can somebody tell my why, thanks you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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