aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/cgo/main.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-01-27 12:43:45 +0100
committerRon Evans <[email protected]>2024-08-10 23:46:58 -0700
commit2eb39785fe9d0188e444fd1eb29f1ce2c7a89419 (patch)
treed44479528d48558526a788d0d519b37f5735837e /testdata/cgo/main.go
parent3021e16bbf138ef48d840604e330049def61329a (diff)
downloadtinygo-2eb39785fe9d0188e444fd1eb29f1ce2c7a89419.tar.gz
tinygo-2eb39785fe9d0188e444fd1eb29f1ce2c7a89419.zip
cgo: add support for printf
The C printf function is sometimes needed for C files included using CGo. This commit makes sure they're available on all systems where CGo is fully supported (that is, everywhere except on AVR). For baremetal systems using picolibc, I've picked the integer-only version of printf to save on flash size. We might want to consider providing a way to pick the floating point version instead, if needed.
Diffstat (limited to 'testdata/cgo/main.go')
-rw-r--r--testdata/cgo/main.go4
1 files changed, 4 insertions, 0 deletions
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 {