mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 03:27:48 +00:00
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();
This commit is contained in:
committed by
Ron Evans
parent
5502182642
commit
2e9c3a1d8d
Vendored
+8
@@ -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;
|
||||
}
|
||||
|
||||
Vendored
+4
@@ -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
|
||||
|
||||
Vendored
+3
@@ -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
|
||||
|
||||
Vendored
+2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user