github.com/mh-cbon/go@v0.0.0-20160603070303-9e112a3fe4c0/misc/cgo/test/api.go (about)

     1  // Copyright 2013 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.
     4  
     5  // API Compatibility Checks for cgo
     6  
     7  package cgotest
     8  
     9  // #include <stdlib.h>
    10  // const char *api_hello = "hello!";
    11  import "C"
    12  import "unsafe"
    13  
    14  func testAPI() {
    15  	var cs *C.char
    16  	cs = C.CString("hello")
    17  	defer C.free(unsafe.Pointer(cs))
    18  	var s string
    19  	s = C.GoString((*C.char)(C.api_hello))
    20  	s = C.GoStringN((*C.char)(C.api_hello), C.int(6))
    21  	var b []byte
    22  	b = C.GoBytes(unsafe.Pointer(C.api_hello), C.int(6))
    23  	_, _ = s, b
    24  }