Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace System;
- int main() {
- int array1[2] = {0, 0};
- int *array2 = new int[2]();
- array2[0] = 0;
- array2[1] = 0;
- #pragma pack(1)
- struct testStruct {
- // Word 0 (desired)
- unsigned a : 8;
- unsigned b : 1;
- bool c : 1;
- unsigned d : 21;
- bool e : 1;
- // Word 1 (desired)
- int f : 32;
- // Words 2-3 (desired)
- int g[2]; //Cannot assign bit field but takes 64 bits in my compiler
- };
- testStruct test;
- Console::WriteLine("size of char: {0:D}", sizeof(char) * 8);
- Console::WriteLine("size of short: {0:D}", sizeof(short) * 8);
- Console::WriteLine("size of int: {0:D}", sizeof(int) * 8);
- Console::WriteLine("size of unsigned: {0:D}", sizeof(unsigned) * 8);
- Console::WriteLine("size of long: {0:D}", sizeof(long) * 8);
- Console::WriteLine("size of long long: {0:D}", sizeof(long long) * 8);
- Console::WriteLine("size of bool: {0:D}", sizeof(bool) * 8);
- Console::WriteLine("size of int[2]: {0:D}", sizeof(array1) * 8);
- Console::WriteLine("size of int*: {0:D}", sizeof(array2) * 8);
- Console::WriteLine("size of testStruct: {0:D}", sizeof(testStruct) * 8);
- Console::WriteLine("size of test: {0:D}", sizeof(test) * 8);
- Console::ReadKey(true);
- delete[] array2;
- return 0;
- }
- size of char: 8
- size of short: 16
- size of int: 32
- size of unsigned: 32
- size of long: 32
- size of long long: 64
- size of bool: 8
- size of int[2]: 64
- size of int*: 32
- size of testStruct: 224
- size of test: 224
- #pragma pack( push, 1 )
- struct testStruct {
- // Word 0 (desired)
- unsigned a : 8;
- unsigned b : 1;
- unsigned c : 1;
- unsigned d : 21;
- unsigned e : 1;
- // Word 1 (desired)
- unsigned f : 32;
- // Words 2-3 (desired)
- unsigned g[2]; //Cannot assign bit field but takes 64 bits in my compiler
- };
- #pragma pack(pop)
Add Comment
Please, Sign In to add comment