1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
6 A trivial example of wrapping a C library in Go.
7 For a more complex example and explanation,
8 see misc/cgo/gmp/gmp.go.
19 char* greeting = "hello, world";
26 // Test reference to library symbol.
27 // Stdout and stderr are too special to be a reliable test.
30 func (f *File) WriteString(s string) {
32 C.fputs(p, (*C.FILE)(f))
33 C.free(unsafe.Pointer(p))
37 func (f *File) Flush() {
38 C.fflush((*C.FILE)(f))
41 var Greeting = C.GoString(C.greeting)
42 var Gbytes = C.GoBytes(unsafe.Pointer(C.greeting), C.int(len(Greeting)))