tbitsize.nim 314 B

1234567891011121314151617181920212223
  1. discard """
  2. ccodeCheck: "\\i @'unsigned int flag:1;' .*"
  3. """
  4. type
  5. bits* = object
  6. flag* {.bitsize: 1.}: cuint
  7. opts* {.bitsize: 4.}: cint
  8. var
  9. b: bits
  10. doAssert b.flag == 0
  11. b.flag = 1
  12. doAssert b.flag == 1
  13. b.flag = 2
  14. doAssert b.flag == 0
  15. b.opts = 7
  16. doAssert b.opts == 7
  17. b.opts = 9
  18. doAssert b.opts == -7