[ create a new paste ] login | about

Project: boost
Link: http://boost.codepad.org/zoiC0K2I    [ raw code | output | fork ]

C++, pasted on Nov 4:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
struct foo
{
    char c;
    short s;
    void* p;
    int i;
};

int main()
{
    cout << "sizeof(foo)=" << sizeof(foo) << endl;
    foo f;
    cout << "address of c: " << reinterpret_cast<void*>(&f.c) << endl;
    cout << "address of s: " << reinterpret_cast<void*>(&f.s) << endl;
    cout << "address of p: " << reinterpret_cast<void*>(&f.p) << endl;
    cout << "address of i: " << reinterpret_cast<void*>(&f.i) << endl;
    cout << "distance between s and c: " << reinterpret_cast<char*>(&f.s) - reinterpret_cast<char*>(&f.c) << endl;
    cout << "distance between p and s: " << reinterpret_cast<char*>(&f.p) - reinterpret_cast<char*>(&f.s) << endl;
    cout << "distance between p and c: " << reinterpret_cast<char*>(&f.p) - reinterpret_cast<char*>(&f.c) << endl;
    cout << "distance between i and p: " << reinterpret_cast<char*>(&f.i) - reinterpret_cast<char*>(&f.p) << endl;
}


Output:
1
2
3
4
5
6
7
8
9
sizeof(foo)=12
address of c: 0xbfb52d84
address of s: 0xbfb52d86
address of p: 0xbfb52d88
address of i: 0xbfb52d8c
distance between s and c: 2
distance between p and s: 2
distance between p and c: 4
distance between i and p: 4


Create a new paste based on this one


Comments: