mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:22:22 +00:00
32 lines
411 B
Go
32 lines
411 B
Go
package main
|
|
|
|
/*
|
|
#include <stdint.h>
|
|
|
|
int64_t myadd(int64_t a, int64_t b) {
|
|
return a+b;
|
|
}
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"asmpkg"
|
|
"fmt"
|
|
"runtime"
|
|
"unsafe"
|
|
)
|
|
|
|
func main() {
|
|
if runtime.GOOS == "windows" {
|
|
fmt.Println(asmpkg.CallCAdd_Win64_ABI(
|
|
uintptr(unsafe.Pointer(C.myadd)),
|
|
123, 456,
|
|
))
|
|
} else {
|
|
fmt.Println(asmpkg.CallCAdd_SystemV_ABI(
|
|
uintptr(unsafe.Pointer(C.myadd)),
|
|
123, 456,
|
|
))
|
|
}
|
|
}
|