File: tobjpragma.nim

package info (click to toggle)
nim 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 462,356 kB
  • sloc: sh: 11,089; ansic: 4,699; makefile: 706; python: 309; sql: 297; asm: 141; xml: 13
file content (52 lines) | stat: -rw-r--r-- 591 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
discard """
  file: "tobjpragma.nim"
  output: '''2
3
9
257
1
2
3'''
  disabled: "true"
"""

# Disabled since some versions of GCC ignore the 'packed' attribute

# Test

type
  Foo {.packed.} = object
    a: int8
    b: int8

  Bar {.packed.} = object
    a: int8
    b: int16

  Daz {.packed.} = object
    a: int32
    b: int8
    c: int32


var f = Foo(a: 1, b: 1)
var b: Bar
var d: Daz

echo sizeof(f)
echo sizeof(b)
echo sizeof(d)
echo (cast[ptr int16](f.addr)[])

type
  Union {.union.} = object
    a: int8
    b: int8

var u: Union
u.a = 1
echo u.b
u.a = 2
echo u.b
u.b = 3
echo u.a