Re: Strcut padding?

Discussion in 'C++' started by diligent.snail@gmail.com, Feb 23, 2008.

  1. Guest

    On Feb 23, 2:58 am, "" <>
    wrote:
    > #include <iostream>
    > #include <string>
    >
    > using namespace std;
    >
    > int main() {
    > char t1;
    > struct t2{
    > char x;
    > };
    >
    > cout << sizeof(t1) << " " << sizeof(t2) << endl;
    >
    > typedef char& x1;
    > struct x2{
    > x1 x;
    > };
    >
    > cout << sizeof(x1) << " " << sizeof(x2) << endl;
    >
    > }
    >
    > output:
    > 1 1
    > 1 4
    >
    > Can anybody tell me why the size of x2 is 4? Why it's not 1?


    Hello,

    This question was answered here:
    http://groups.google.com/group/alt....read/thread/966f53a973231120/0efafb62332dd4b7
    (in particular Karl Heinz Buchegger's answer)

    It all comes down to the fact that the implementation of a reference
    is compiler dependent, and a compiler may use a pointer to implement
    reference semantics (which probably explains size of 4 bytes).

    Regards.
     
    , Feb 23, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave
    Replies:
    7
    Views:
    5,669
    Joe Smith
    Jul 22, 2004
  2. RA
    Replies:
    1
    Views:
    376
  3. Becker

    Padding between textboxes

    Becker, Jun 24, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,295
    Eliyahu Goldin
    Jun 24, 2004
  4. Strcut padding?

    , Feb 23, 2008, in forum: C++
    Replies:
    1
    Views:
    399
    EventHelix.com
    Feb 27, 2008
  5. Mateusz_madi

    How to use maloc with strcut

    Mateusz_madi, May 13, 2010, in forum: C Programming
    Replies:
    2
    Views:
    822
    Mateusz_madi
    May 13, 2010
Loading...

Share This Page