Guest User

Untitled

a guest
Jan 23rd, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. using namespace System;
  2. int main() {
  3. int array1[2] = {0, 0};
  4. int *array2 = new int[2]();
  5. array2[0] = 0;
  6. array2[1] = 0;
  7.  
  8. #pragma pack(1)
  9. struct testStruct {
  10. // Word 0 (desired)
  11. unsigned a : 8;
  12. unsigned b : 1;
  13. bool c : 1;
  14. unsigned d : 21;
  15. bool e : 1;
  16.  
  17. // Word 1 (desired)
  18. int f : 32;
  19.  
  20. // Words 2-3 (desired)
  21. int g[2]; //Cannot assign bit field but takes 64 bits in my compiler
  22. };
  23. testStruct test;
  24.  
  25. Console::WriteLine("size of char: {0:D}", sizeof(char) * 8);
  26. Console::WriteLine("size of short: {0:D}", sizeof(short) * 8);
  27. Console::WriteLine("size of int: {0:D}", sizeof(int) * 8);
  28. Console::WriteLine("size of unsigned: {0:D}", sizeof(unsigned) * 8);
  29. Console::WriteLine("size of long: {0:D}", sizeof(long) * 8);
  30. Console::WriteLine("size of long long: {0:D}", sizeof(long long) * 8);
  31. Console::WriteLine("size of bool: {0:D}", sizeof(bool) * 8);
  32. Console::WriteLine("size of int[2]: {0:D}", sizeof(array1) * 8);
  33. Console::WriteLine("size of int*: {0:D}", sizeof(array2) * 8);
  34. Console::WriteLine("size of testStruct: {0:D}", sizeof(testStruct) * 8);
  35. Console::WriteLine("size of test: {0:D}", sizeof(test) * 8);
  36.  
  37. Console::ReadKey(true);
  38.  
  39. delete[] array2;
  40. return 0;
  41. }
  42.  
  43. size of char: 8
  44. size of short: 16
  45. size of int: 32
  46. size of unsigned: 32
  47. size of long: 32
  48. size of long long: 64
  49. size of bool: 8
  50. size of int[2]: 64
  51. size of int*: 32
  52. size of testStruct: 224
  53. size of test: 224
  54.  
  55. #pragma pack( push, 1 )
  56. struct testStruct {
  57. // Word 0 (desired)
  58. unsigned a : 8;
  59. unsigned b : 1;
  60. unsigned c : 1;
  61. unsigned d : 21;
  62. unsigned e : 1;
  63.  
  64. // Word 1 (desired)
  65. unsigned f : 32;
  66.  
  67. // Words 2-3 (desired)
  68. unsigned g[2]; //Cannot assign bit field but takes 64 bits in my compiler
  69. };
  70. #pragma pack(pop)
Add Comment
Please, Sign In to add comment