// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH04_Expressions/examples/sizeof_pgm.cc
// Function: main
int main() 
{
	Sales_data data, *p;
	sizeof(Sales_data); // size required to hold an object of type Sales_data 
	sizeof data; // size of data's type, i.e., sizeof(Sales_data)
	sizeof p;    // size of a pointer
	sizeof *p;   // size of the type to which p points, i.e., sizeof(Sales_data)
	sizeof data.revenue; // size of the type of Sales_data's revenue member 
	sizeof Sales_data::revenue; // alternative way to get the size of revenue
	
	cout << "short: " << sizeof(short) << "\n"
	     << "short[3]: " << sizeof(short[3]) << "\n"
	     << "short*: " << sizeof(short*) << "\n"
	     << "short&: " << sizeof(short&) << endl;
	
	cout << endl; 
	
	cout << "int: " << sizeof(int) << "\n"
	     << "int[3]: " << sizeof(int[3]) << "\n"
	     << "int*: " << sizeof(int*) << "\n"
	     << "int&: " << sizeof(int&) << endl;
	
	cout << endl; 
	
	cout << "Sales_data: " << sizeof(Sales_data) << "\n"
	     << "Sales_data[3]: " << sizeof(Sales_data[3]) << "\n"
	     << "Sales_data*: " << sizeof(Sales_data*) << "\n"
	     << "Sales_data&: " << sizeof(Sales_data&) << endl;
	
	cout << "Sales_data::revenue: " << sizeof Sales_data::revenue << "\n"
	     << "data.revenue: " << sizeof data.revenue << endl;

	int x[10];   
	int *ip = x;

	// number of elements in x
	cout << sizeof(x)/sizeof(*x) << endl;

	// divides sizeof a pointer by sizeof an int
	cout << sizeof(ip)/sizeof(*ip) << endl;
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x38, %rsp
leaq -0x28(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
andl $0x0, 0x10(%rax)
andq $0x0, 0x18(%rax)
movq 0x2dd3(%rip), %rdi      # 0x3fd8
leaq 0xdf8(%rip), %rsi       # 0x2004
callq 0x1070
pushq $0x2
popq %rsi
movq %rax, %rdi
callq 0x1050
leaq 0xde9(%rip), %rsi       # 0x200c
movq %rax, %rdi
callq 0x1070
leaq 0xddc(%rip), %rsi       # 0x200e
movq %rax, %rdi
callq 0x1070
pushq $0x6
popq %rsi
movq %rax, %rdi
callq 0x1050
leaq 0xdc0(%rip), %rsi       # 0x200c
movq %rax, %rdi
callq 0x1070
leaq 0xdbe(%rip), %rsi       # 0x2019
movq %rax, %rdi
callq 0x1070
pushq $0x8
popq %rsi
movq %rax, %rdi
callq 0x1050
leaq 0xd97(%rip), %rsi       # 0x200c
movq %rax, %rdi
callq 0x1070
leaq 0xd9e(%rip), %rsi       # 0x2022
movq %rax, %rdi
callq 0x1070
pushq $0x2
popq %rsi
movq %rax, %rdi
callq 0x1050
movq %rax, %rdi
callq 0x1040
movq 0x2d32(%rip), %rdi      # 0x3fd8
callq 0x1040
movq 0x2d26(%rip), %rdi      # 0x3fd8
leaq 0xd72(%rip), %rsi       # 0x202b
callq 0x1070
pushq $0x4
popq %rsi
movq %rax, %rdi
callq 0x1050
leaq 0xd3c(%rip), %rsi       # 0x200c
movq %rax, %rdi
callq 0x1070
leaq 0xd52(%rip), %rsi       # 0x2031
movq %rax, %rdi
callq 0x1070
pushq $0xc
popq %rsi
movq %rax, %rdi
callq 0x1050
leaq 0xd13(%rip), %rsi       # 0x200c
movq %rax, %rdi
callq 0x1070
leaq 0xd32(%rip), %rsi       # 0x203a
movq %rax, %rdi
callq 0x1070
pushq $0x8
popq %rsi
movq %rax, %rdi
callq 0x1050
leaq 0xcea(%rip), %rsi       # 0x200c
movq %rax, %rdi
callq 0x1070
leaq 0xd10(%rip), %rsi       # 0x2041
movq %rax, %rdi
callq 0x1070
pushq $0x4
popq %rsi
movq %rax, %rdi
callq 0x1050
movq %rax, %rdi
callq 0x1040
movq 0x2c85(%rip), %rdi      # 0x3fd8
callq 0x1040
movq 0x2c79(%rip), %rdi      # 0x3fd8
leaq 0xce2(%rip), %rsi       # 0x2048
callq 0x1070
pushq $0x30
popq %rsi
movq %rax, %rdi
callq 0x1050
leaq 0xc8f(%rip), %rsi       # 0x200c
movq %rax, %rdi
callq 0x1070
leaq 0xcc9(%rip), %rsi       # 0x2055
movq %rax, %rdi
callq 0x1070
movl $0x90, %esi
movq %rax, %rdi
callq 0x1050
leaq 0xc64(%rip), %rsi       # 0x200c
movq %rax, %rdi
callq 0x1070
leaq 0xcae(%rip), %rsi       # 0x2065
movq %rax, %rdi
callq 0x1070
pushq $0x8
popq %rsi
movq %rax, %rdi
callq 0x1050
leaq 0xc3b(%rip), %rsi       # 0x200c
movq %rax, %rdi
callq 0x1070
leaq 0xc93(%rip), %rsi       # 0x2073
movq %rax, %rdi
callq 0x1070
pushq $0x30
popq %rsi
movq %rax, %rdi
callq 0x1050
movq %rax, %rdi
callq 0x1040
movq 0x2bd6(%rip), %rdi      # 0x3fd8
leaq 0xc78(%rip), %rsi       # 0x2081
callq 0x1070
pushq $0x8
popq %rsi
movq %rax, %rdi
callq 0x1050
leaq 0xbec(%rip), %rsi       # 0x200c
movq %rax, %rdi
callq 0x1070
leaq 0xc68(%rip), %rsi       # 0x2097
movq %rax, %rdi
callq 0x1070
pushq $0x8
popq %rsi
movq %rax, %rdi
callq 0x1050
movq %rax, %rdi
callq 0x1040
movq 0x2b87(%rip), %rdi      # 0x3fd8
pushq $0xa
popq %rsi
callq 0x1050
movq %rax, %rdi
callq 0x1040
movq 0x2b70(%rip), %rdi      # 0x3fd8
pushq $0x2
popq %rsi
callq 0x1050
movq %rax, %rdi
callq 0x1040
leaq -0x38(%rbp), %rdi
callq 0x1030
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %rbp
retq
jmp 0x148c
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1090