diff options
author | Ayke van Laethem <[email protected]> | 2021-02-07 16:02:16 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-02-11 09:51:15 +0100 |
commit | 2e9c3a1d8d5e59baee62ce12812f0ef37d112f33 (patch) | |
tree | 3f89a557d312c69c1466b0931a8ea22912551268 /testdata/cgo | |
parent | 550218264204aa62e9d602a1a380531040c18deb (diff) | |
download | tinygo-2e9c3a1d8d5e59baee62ce12812f0ef37d112f33.tar.gz tinygo-2e9c3a1d8d5e59baee62ce12812f0ef37d112f33.zip |
cgo: add support for variadic functions
This doesn't yet add support for actually making use of variadic
functions, but at least allows (unintended) variadic functions like the
following to work:
void foo();
Diffstat (limited to 'testdata/cgo')
-rw-r--r-- | testdata/cgo/main.c | 8 | ||||
-rw-r--r-- | testdata/cgo/main.go | 4 | ||||
-rw-r--r-- | testdata/cgo/main.h | 3 | ||||
-rw-r--r-- | testdata/cgo/out.txt | 2 |
4 files changed, 17 insertions, 0 deletions
diff --git a/testdata/cgo/main.c b/testdata/cgo/main.c index 8f3b09464..3a2e9c57e 100644 --- a/testdata/cgo/main.c +++ b/testdata/cgo/main.c @@ -34,6 +34,14 @@ int doCallback(int a, int b, binop_t callback) { return callback(a, b); } +int variadic0() { + return 1; +} + +int variadic2(int x, int y, ...) { + return x * y; +} + void store(int value, int *ptr) { *ptr = value; } diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go index 616bc5bfc..d9e2d7297 100644 --- a/testdata/cgo/main.go +++ b/testdata/cgo/main.go @@ -36,6 +36,10 @@ func main() { cb = C.binop_t(C.mul) println("callback 2:", C.doCallback(20, 30, cb)) + // variadic functions + println("variadic0:", C.variadic0()) + println("variadic2:", C.variadic2(3, 5)) + // equivalent types var goInt8 int8 = 5 var _ C.int8_t = goInt8 diff --git a/testdata/cgo/main.h b/testdata/cgo/main.h index b4ac4ee88..857a796ef 100644 --- a/testdata/cgo/main.h +++ b/testdata/cgo/main.h @@ -10,6 +10,9 @@ int doCallback(int a, int b, binop_t cb); typedef int * intPointer; void store(int value, int *ptr); +int variadic0(); +int variadic2(int x, int y, ...); + # define CONST_INT 5 # define CONST_INT2 5llu # define CONST_FLOAT 5.8 diff --git a/testdata/cgo/out.txt b/testdata/cgo/out.txt index 9da7386a1..31fd4d330 100644 --- a/testdata/cgo/out.txt +++ b/testdata/cgo/out.txt @@ -12,6 +12,8 @@ defined char: 99 25: 25 callback 1: 50 callback 2: 600 +variadic0: 1 +variadic2: 15 bool: true true float: +3.100000e+000 double: +3.200000e+000 |