class B {
public:
int b1;
int b2;
};
class F {
public:
int f1;
int f2;
};
class D : public B, public F {
public:
int d1;
int d2;
};
D *d = new D ();
d->d1 = 1419;
d->d2 = 7292;
d->f1 = 9032;
d->f2 = 3293;
d->b1 = 2948;
d->b2 = 8432;
B *b = d;
int x1 = b->b1;
int x2 = b->b2;
F *f = d;
int y1 = f->f1;
int y2 = f->f2;
|
|
movq -8(%rbp), %rax
movl $1419, 16(%rax)
movq -8(%rbp), %rax
movl $7292, 20(%rax)
movq -8(%rbp), %rax
movl $9032, 8(%rax)
movq -8(%rbp), %rax
movl $3293, 12(%rax)
movq -8(%rbp), %rax
movl $2948, (%rax)
movq -8(%rbp), %rax
movl $8432, 4(%rax)
; B *b = (B*) d
movq -8(%rbp), %rax
movq %rax, -16(%rbp)
; int x1 = b->b1
movq -16(%rbp), %rax
movl (%rax), %eax
movl %eax, -20(%rbp)
; int x2 = b->b2
movq -16(%rbp), %rax
movl 4(%rax), %eax
movl %eax, -24(%rbp)
; F *f = (F*) d
; null handling omitted
movq -8(%rbp), %rax
addq $8, %rax
movq %rax, -32(%rbp)
; int y1 = f->f1
movq -32(%rbp), %rax
movl (%rax), %eax
movl %eax, -36(%rbp)
; int y2 = f->f2
movq -32(%rbp), %rax
movl 4(%rax), %eax
movl %eax, -40(%rbp)
|
|
Layout of Stack
|
Offset
|
Contents
|
-8(%rbp)
|
local variable D *d
|
-16(%rbp)
|
local variable B *b
|
-20(%rbp)
|
local variable int x1
|
-24(%rbp)
|
local variable int x2
|
-32(%rbp)
|
local variable F *f
|
-36(%rbp)
|
local variable int y1
|
-40(%rbp)
|
local variable int y2
|
Layout of Instance of D
|
Offset
|
Name
|
Contents
|
20 | d2 | 7292 |
16 | d1 | 1419 |
12 | f2 | 3293 |
8 | f1 | 9032 |
4 | b2 | 8432 |
0 | b1 | 2948 |
|