Linux 1 g + + 4.8.1 version
# include & lt; Iostream>
2
3 using namespace STD.
4
5 struct A
6 {
Char a;
8 long double b;
9 int c;
10};
11.
12
13 int main ()
14 {
15 cout & lt;
19}
The output
Vs2012 code
# include & lt; Iostream>
using namespace std;
Struct A
{
char a;
Long double b;
Int c;
};
Int main ()
{
cout
cin> i;
}
Results:
Analysis: use # pragma pack (n) adjust the byte order of no doubt, but the default byte order is a little small doubt
1 the Internet is GCC 4 byte alignment, vc is 8 byte alignment, according to the analysis results of the first output has a problem,
2 if not in accordance with the default byte alignment, the alignment according to structure the maximum length, exactly the both results, this understanding is wrong?
CodePudding user response:
CodePudding user response:
The above is the g + +V output
CodePudding user response:
Who can help answer, thank youCodePudding user response:
This uncertainty or with the compiler or the # pragma pack (1, 4 or 8)CodePudding user response:
# pack is no problem# but not to bring a pack of GCC is also the default not 8, 48 is or how?
CodePudding user response:
The default # not pack (4)CodePudding user response:
GCC sizeof (long double) is equal to the 48?And, in turn, sizeof (long double) equal to 16, sizeof (A) equal to 48?
GCC should be 64?
You do not have a unified code before and after,
CodePudding user response:
Is right, I didn't delete sizeof B A is 48. The long double is 16, according to the online GCC default 4 bytes aligned understand feeling not ahCodePudding user response:
System is Centos, forget how much is a, should be 6.4 64CodePudding user response:
Long double types of element's address will be aligned to sizeof (long double) multiples,If long double is 16, sizeof (A) by default size is 48, otherwise A A [2], the second element of array b members cannot be aligned to 16 times,
CodePudding user response: