From 12237a8e9a85bc0cd8512a46e40583f300e0f2e1 Mon Sep 17 00:00:00 2001 From: yanfeizhang <54074852@qq.com> Date: Wed, 24 Apr 2024 09:01:53 +0800 Subject: [PATCH] up --- tests/cpu/index.md | 3 ++- tests/cpu/test10/main.c | 9 +++++++++ tests/cpu/test10/main.go | 12 ++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/cpu/test10/main.c create mode 100644 tests/cpu/test10/main.go diff --git a/tests/cpu/index.md b/tests/cpu/index.md index 5f8d988..1c4bfe9 100644 --- a/tests/cpu/index.md +++ b/tests/cpu/index.md @@ -2,4 +2,5 @@ - [物理机 cpu 系统利用率的计算过程](tests/cpu/test06) - [容器 cpu 系统利用率的计算过程](tests/cpu/test07) - [直接使用perf_event_open获取硬件计数](tests/cpu/test08) -- [火焰图专用测试代码](tests/cpu/test09) \ No newline at end of file +- [火焰图专用测试代码](tests/cpu/test09) +- [C语言调用Golang函数原理](tests/cpu/test10) \ No newline at end of file diff --git a/tests/cpu/test10/main.c b/tests/cpu/test10/main.c new file mode 100644 index 0000000..ceb4198 --- /dev/null +++ b/tests/cpu/test10/main.c @@ -0,0 +1,9 @@ +#include +#include "libadd.h" + +int main(void) +{ + int ret = add(2,3); + printf("C调用Go函数2+3=%d", ret); + return 0; +} \ No newline at end of file diff --git a/tests/cpu/test10/main.go b/tests/cpu/test10/main.go new file mode 100644 index 0000000..b0a44d4 --- /dev/null +++ b/tests/cpu/test10/main.go @@ -0,0 +1,12 @@ +package main + +//int add(int a, int b); +import "C" + +//export add +func add(a, b C.int) C.int { + return a + b +} + +func main() { +}