tobjpragma.nim 566 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. discard """
  2. output: '''
  3. 2
  4. 3
  5. 9
  6. 257
  7. 1
  8. 2
  9. 3
  10. '''
  11. disabled: "true"
  12. """
  13. # Disabled since some versions of GCC ignore the 'packed' attribute
  14. # Test
  15. type
  16. Foo {.packed.} = object
  17. a: int8
  18. b: int8
  19. Bar {.packed.} = object
  20. a: int8
  21. b: int16
  22. Daz {.packed.} = object
  23. a: int32
  24. b: int8
  25. c: int32
  26. var f = Foo(a: 1, b: 1)
  27. var b: Bar
  28. var d: Daz
  29. echo sizeof(f)
  30. echo sizeof(b)
  31. echo sizeof(d)
  32. echo (cast[ptr int16](f.addr)[])
  33. type
  34. Union {.union.} = object
  35. a: int8
  36. b: int8
  37. var u: Union
  38. u.a = 1
  39. echo u.b
  40. u.a = 2
  41. echo u.b
  42. u.b = 3
  43. echo u.a