aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/cgo/main.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-03-03 20:53:45 +0100
committerRon Evans <[email protected]>2024-05-29 21:51:39 +0200
commitc383a407e337f08831efd196bae708977a393028 (patch)
tree06f40139b0fd94552189d715ff5f64cb1a3328b5 /testdata/cgo/main.go
parent7b7601d77c681a3c2ce53ce3f89dbdfc35eec492 (diff)
downloadtinygo-c383a407e337f08831efd196bae708977a393028.tar.gz
tinygo-c383a407e337f08831efd196bae708977a393028.zip
cgo: do a basic test that math functions work
They should, but we weren't testing this. I discovered this while working on https://github.com/tinygo-org/macos-minimal-sdk/pull/4 which will likely make math.h not work anymore. So I wanted to make sure we have a test in place before we update that dependency.
Diffstat (limited to 'testdata/cgo/main.go')
-rw-r--r--testdata/cgo/main.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go
index aac5221f4..fa3380bce 100644
--- a/testdata/cgo/main.go
+++ b/testdata/cgo/main.go
@@ -2,6 +2,7 @@ package main
/*
#include <stdio.h>
+#include <math.h>
int fortytwo(void);
#include "main.h"
#include "test.h"
@@ -171,6 +172,10 @@ func main() {
C.strcpy((*C.char)(unsafe.Pointer(&buf2[0])), (*C.char)(unsafe.Pointer(&buf1[0])))
println("copied string:", string(buf2[:C.strlen((*C.char)(unsafe.Pointer(&buf2[0])))]))
+ // libc: test libm functions (normally bundled in libc)
+ println("CGo sqrt(3):", C.sqrt(3))
+ println("C sqrt(3):", C.doSqrt(3))
+
// libc: test basic stdio functionality
putsBuf := []byte("line written using C puts\x00")
C.puts((*C.char)(unsafe.Pointer(&putsBuf[0])))