1
2
3
4
5 package main
6
7 import "unsafe"
8
9 const (
10 smallInt = 42
11
12
13
14
15
16 bigInt = 0xffffffffffffffff
17
18 stringVal = "test"
19
20 longStringVal = "this_is_a_string_constant_longer_than_seventy_characters_which_used_to_fail_see_issue_50253"
21 )
22
23 var (
24 smallIntAsm int64
25 bigIntAsm uint64
26 stringAsm [len(stringVal)]byte
27 longStringAsm [len(longStringVal)]byte
28 )
29
30 type typ struct {
31 a uint64
32 b [100]uint8
33 c uint8
34 }
35
36 var (
37 typSize uint64
38
39 typA, typB, typC uint64
40 )
41
42 func main() {
43 if smallInt != smallIntAsm {
44 println("smallInt", smallInt, "!=", smallIntAsm)
45 }
46 if bigInt != bigIntAsm {
47 println("bigInt", uint64(bigInt), "!=", bigIntAsm)
48 }
49 if stringVal != string(stringAsm[:]) {
50 println("stringVal", stringVal, "!=", string(stringAsm[:]))
51 }
52 if longStringVal != string(longStringAsm[:]) {
53 println("longStringVal", longStringVal, "!=", string(longStringAsm[:]))
54 }
55
56
57
58
59
60 if want := unsafe.Sizeof(typ{}); want != uintptr(typSize) {
61 println("typSize", want, "!=", typSize)
62 }
63 if want := unsafe.Offsetof(typ{}.a); want != uintptr(typA) {
64 println("typA", want, "!=", typA)
65 }
66 if want := unsafe.Offsetof(typ{}.b); want != uintptr(typB) {
67 println("typB", want, "!=", typB)
68 }
69 if want := unsafe.Offsetof(typ{}.c); want != uintptr(typC) {
70 println("typC", want, "!=", typC)
71 }
72 }
73
View as plain text