aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
Diffstat (limited to 'testdata')
-rw-r--r--testdata/cgo/main.c5
-rw-r--r--testdata/cgo/main.go4
-rw-r--r--testdata/cgo/main.h2
-rw-r--r--testdata/cgo/out.txt1
4 files changed, 12 insertions, 0 deletions
diff --git a/testdata/cgo/main.c b/testdata/cgo/main.c
index 7fb702ed6..4a5bd6b9c 100644
--- a/testdata/cgo/main.c
+++ b/testdata/cgo/main.c
@@ -1,5 +1,6 @@
#include <math.h>
#include "main.h"
+#include <stdio.h>
int global = 3;
bool globalBool = 1;
@@ -72,3 +73,7 @@ void arraydecay(int buf1[5], int buf2[3][8], int buf3[4][7][2]) {
double doSqrt(double x) {
return sqrt(x);
}
+
+void printf_single_int(char *format, int arg) {
+ printf(format, arg);
+}
diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go
index fa3380bce..ddd1992e2 100644
--- a/testdata/cgo/main.go
+++ b/testdata/cgo/main.go
@@ -179,6 +179,10 @@ func main() {
// libc: test basic stdio functionality
putsBuf := []byte("line written using C puts\x00")
C.puts((*C.char)(unsafe.Pointer(&putsBuf[0])))
+
+ // libc: test whether printf works in C.
+ printfBuf := []byte("line written using C printf with value=%d\n\x00")
+ C.printf_single_int((*C.char)(unsafe.Pointer(&printfBuf[0])), -21)
}
func printUnion(union C.joined_t) C.joined_t {
diff --git a/testdata/cgo/main.h b/testdata/cgo/main.h
index f5405ade6..e7c64ffc3 100644
--- a/testdata/cgo/main.h
+++ b/testdata/cgo/main.h
@@ -152,3 +152,5 @@ typedef int arraydecay_buf3[4][7][2];
void arraydecay(int buf1[5], int buf2[3][8], arraydecay_buf3 buf3);
double doSqrt(double);
+
+void printf_single_int(char *format, int arg);
diff --git a/testdata/cgo/out.txt b/testdata/cgo/out.txt
index ae92c87a7..4ea45d864 100644
--- a/testdata/cgo/out.txt
+++ b/testdata/cgo/out.txt
@@ -77,3 +77,4 @@ copied string: foobar
CGo sqrt(3): +1.732051e+000
C sqrt(3): +1.732051e+000
line written using C puts
+line written using C printf with value=-21