[gambit-list] How to return multiple "double" values from a C function ?
Ryuho Yokoyama
ryuho8 at gmail.com
Sun Dec 22 07:30:59 EST 2019
[gambit-list] FFI C out parameters
https://mailman.iro.umontreal.ca/pipermail/gambit-list/2015-January/007696.html
According to the mailing list entry above:
multiple "int" values:
----------
(c-declare "
void add_mul(int x, int y, ___SCMOBJ res) {
int add = x+y;
int mul = x*y;
___VECTORSET(res, ___FIX(0), ___FIX(add))
___VECTORSET(res, ___FIX(1), ___FIX(mul))
}
")
(define (add-mul x y)
(let ((res (vector 0 0)))
((c-lambda (int int scheme-object) void "add_mul") x y res)
(values (vector-ref res 0)
(vector-ref res 1))))
(receive (add mul) (add-mul 3 7)
(pp (list 'add= add 'mul= mul)))
;; prints: (add= 10 mul= 21)
----------
In an example code, C function is returning multiple "int" values.
How to write an example code returning multiple "double" values from a C
function ?
multiple "double" values:
----------
(c-declare "
void add_mul(double x, double y, ___SCMOBJ res) {
double add = x+y;
double mul = x*y;
___F64VECTORSET(res, ___FIX(0), ___???(add))
___F64VECTORSET(res, ___FIX(1), ___???(mul))
}
")
(define (add-mul x y)
(let ((res (vector 0 0)))
((c-lambda (double double scheme-object) void "add_mul") x y res)
(values (vector-ref res 0)
(vector-ref res 1))))
(receive (add mul) (add-mul 3.5 7.0)
(pp (list 'add= add 'mul= mul)))
;; prints: (add= 10.5 mul= 24.5)
----------
___F64VECTORSET(res, ___FIX(0), ___???(add))
↑ ↑
?? ??
1) Is it possible to use ___F64VECTORSET macro instead of ___VECTORSET
macro ?
2) Is it possible to define a ___F64(x) macro like a macro ___FIX(x) ?
Thank you very much in advance.
More information about the Gambit-list
mailing list