github.com/kitech/dl@v0.0.0-20201225001532-be4f4faa4070/asmcgocall/examples/single_return.go (about)

     1  package main
     2  
     3  /*
     4  
     5  int ret_value = 666;
     6  
     7  int single_ret(struct {int ret;} *ax) {
     8  
     9  	ax->ret = ret_value;
    10  
    11  	// error code
    12  	return 0;
    13  }
    14  
    15  int regular_single_ret() {
    16  	return ret_value;
    17  }
    18  
    19  */
    20  import "C"
    21  
    22  import (
    23  	"unsafe"
    24  
    25  	"github.com/kitech/dl/asmcgocall"
    26  )
    27  
    28  var singleRetExpected = C.ret_value
    29  
    30  var singleRetAsmcgocall = func() C.int {
    31  	argv := struct{ ret C.int }{}
    32  	asmcgocall.Asmcc(C.single_ret, unsafe.Pointer(&argv))
    33  	return argv.ret
    34  }
    35  
    36  func singleRetCgocall() C.int {
    37  	return C.regular_single_ret()
    38  }