我是Zig的新手,我想使用cImport来调用GNU多精度库GMP。我让它起作用了,但感觉很尴尬,因为Zig显然在默认情况下不会从数组转换到指针,而且GMP使用这种方法通过引用传递。有比我的更干净的方法吗?有现成的例子叫Zig GMP吗?
const gmp = @cImport({
@cInclude("gmp.h");
});
pub fn main() void {
var x: gmp.mpz_t = undefined;
gmp.mpz_init(&x[0]);
gmp.mpz_set_ui(&x[0], 7);
gmp.mpz_mul(&x[0], &x[0], &x[0]);
_ = gmp.gmp_printf("%Zd\n", x);
}发布于 2022-06-09 15:51:15
您应该能够删除[0]
const gmp = @cImport({
@cInclude("gmp.h");
});
pub fn main() void {
var x: gmp.mpz_t = undefined;
gmp.mpz_init(&x);
gmp.mpz_set_ui(&x, 7);
gmp.mpz_mul(&x, &x, &x);
_ = gmp.gmp_printf("%Zd\n", x);
}https://stackoverflow.com/questions/72547917
复制相似问题