2015-11-03 18:15:30 -07:00
|
|
|
// Copyright 2015 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
|
|
|
|
|
|
|
|
/*
|
2015-11-18 22:25:44 -07:00
|
|
|
extern int *GoFn(int *);
|
2015-11-03 18:15:30 -07:00
|
|
|
|
|
|
|
// Yes, you can have definitions if you use //export, as long as they are weak.
|
|
|
|
int f(void) __attribute__ ((weak));
|
|
|
|
|
|
|
|
int f() {
|
2015-11-18 22:25:44 -07:00
|
|
|
int i;
|
|
|
|
int *p = GoFn(&i);
|
2015-11-03 18:15:30 -07:00
|
|
|
if (*p != 12345)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
//export GoFn
|
2015-11-18 22:25:44 -07:00
|
|
|
func GoFn(p *C.int) *C.int {
|
|
|
|
*p = C.int(12345)
|
|
|
|
return p
|
2015-11-03 18:15:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if r := C.f(); r != 1 {
|
|
|
|
panic(r)
|
|
|
|
}
|
|
|
|
}
|