Reputation: 143
I'm a little confused on the current packing scheme in a struct. Take this example
#include <iostream>
using namespace std;
struct Node
{
char c;
double d;
int s;
} Node;
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
cout << sizeof(char) << endl;
cout << sizeof(double) << endl;
cout << sizeof(int) << endl;
cout << sizeof(Node) << endl;
return 0;
}
This is the output:
Hello, World!
1
8
4
24
Program ended with exit code: 0
I understand that there is a certain scheme of packing. However assuming a size of 8. should this be 1+8 +4 + padding shouldn't it be 16, however its being reported as 24. Is there a way I can find out the default value of packing? I am currently using a xcode on a mac that's not too old.
Upvotes: 0
Views: 274