Created
April 3, 2014 05:09
-
-
Save JayXon/9948578 to your computer and use it in GitHub Desktop.
#pragma pack test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#pragma pack(4) | |
struct name | |
{ | |
short a; | |
char b; | |
short c; | |
int d; | |
short e; | |
double f; | |
char g; | |
}; | |
int main() | |
{ | |
name ee; | |
std::cout << sizeof(name) << std::endl; | |
std::cout << (char *)&ee.b-(char *)&ee.a << std::endl; | |
std::cout << (char *)&ee.c-(char *)&ee.b << std::endl; | |
std::cout << (char *)&ee.d-(char *)&ee.c << std::endl; | |
std::cout << (char *)&ee.e-(char *)&ee.d << std::endl; | |
std::cout << (char *)&ee.f-(char *)&ee.e << std::endl; | |
std::cout << (char *)&ee.g-(char *)&ee.f << std::endl; | |
std::cout << sizeof(name) - ((char *)&ee.g - (char *)&ee.a) << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment