2012-02-18 21:15:42 +00:00
|
|
|
// run
|
2010-01-19 02:26:10 +00:00
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import "unsafe"
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// works
|
2010-02-02 07:05:15 +00:00
|
|
|
addr := uintptr(0x234)
|
|
|
|
x1 := (*int)(unsafe.Pointer(addr))
|
2010-01-19 02:26:10 +00:00
|
|
|
|
|
|
|
// fails
|
2010-02-02 07:05:15 +00:00
|
|
|
x2 := (*int)(unsafe.Pointer(uintptr(0x234)))
|
2010-03-24 23:46:53 +00:00
|
|
|
|
2010-02-02 07:05:15 +00:00
|
|
|
if x1 != x2 {
|
2010-03-24 23:46:53 +00:00
|
|
|
println("mismatch", x1, x2)
|
|
|
|
panic("fail")
|
2010-02-02 07:05:15 +00:00
|
|
|
}
|
2010-01-19 02:26:10 +00:00
|
|
|
}
|