Showing the changes to src/scripts/platform.cpp (1 of 158 files). Show all
Unified · Split
| @@ -0,0 +1,32 @@ | |||
| 1 | // name: platform.cpp | ||
| 2 | // desc: finds sizes | ||
| 3 | // author: Ge Wang (gewang@cs.princeton.edu) | ||
| 4 | |||
| 5 | #include <iostream> | ||
| 6 | using namespace std; | ||
| 7 | |||
| 8 | // union | ||
| 9 | union X | ||
| 10 | { | ||
| 11 | short s; | ||
| 12 | char b[2]; | ||
| 13 | }; | ||
| 14 | |||
| 15 | // entry point | ||
| 16 | int main( int argc, char ** argv ) | ||
| 17 | { | ||
| 18 | X x; | ||
| 19 | x.s = 0x0100; | ||
| 20 | |||
| 21 | // go | ||
| 22 | cout << "char: " << sizeof(char) << endl; | ||
| 23 | cout << "short: " << sizeof(short) << endl; | ||
| 24 | cout << "int: " << sizeof(int) << endl; | ||
| 25 | cout << "long: " << sizeof(long) << endl; | ||
| 26 | cout << "float: " << sizeof(float) << endl; | ||
| 27 | cout << "double: " << sizeof(double) << endl; | ||
| 28 | cout << "void *: " << sizeof(void *) << endl; | ||
| 29 | cout << "endian: " << ( x.b[1] ? "small" : "big" ) << endl; | ||
| 30 | |||
| 31 | return 0; | ||
| 32 | } | ||