从https://github.com/bytedeco/javacpp/wiki/Interface-Thrust-and-CUDA,我编写了thrust java 代码。struct 字段默认是公共的,但我使用 first() 方法获取推力::pair 的第一个字段值,发生错误。
错误:明显调用括号前的表达式必须具有(指向)函数类型
错误:宏“offsetof”传递了 3 个参数,但只需要 2 { sizeof(thrust::pair), offsetof(thrust::pair, first) },
那么如何获得推力::对第一个和第二个值?
@Platform(include="<thrust/pair.h>")
@Namespace("thrust")
public class Thrust {
static { Loader.load(); }
@Name("pair<int, double>")
public static class Pair extends Pointer {
static { Loader.load(); }
public Pair(IntPointer key, DoublePointer value){
allocate(key, value);
}
private native void allocate(@ByRef IntPointer k, @ByRef DoublePointer v);
// will happen error: expression preceding parentheses of apparent call must have (pointer-to-) function type
public native IntPointer first();
// will happen error: macro "offsetof" passed 3 arguments, but takes just 2
{ sizeof(thrust::pair<int, double>), offsetof(thrust::pair<int, double>, first) },
public native Pair first(IntPointer p);
}
public static void main(String[] args) {
IntPointer i = new IntPointer(1);
i.put(10);
DoublePointer d = new DoublePointer(1);
d.put(10.0);
Pair p = new Pair(i, d);
System.out.println(p.first());
}
}