0
class Student{
public:
    int id;
    int age;
};
int main() {
    return 0;
}

If we compile such a program using gcc and -fdump-class-hierarchy option, gcc will produce a .class file like this:

Class Student
   size=8 align=4
   base size=8 base align=4
Student (0x0x7fbafc4a05a0) 0

compile command:

g++ file.cpp -o file -fdump-class-hierarchy

Obviously size is class size.but what do align, base align and base size mean in this file?

Amirabbas asadi
  • 182
  • 1
  • 1
  • 7

1 Answers1

0

Alignment relates to where in memory a computer stores its for example an integer, Your student class has two of them. Since an int is generally 4 bytes long it might be much more efficient to load and store when the representation of an int is aligned on a multiple of 4.

hetepeperfan
  • 4,292
  • 1
  • 29
  • 47