【发布时间】:2018-11-27 18:13:59
【问题描述】:
我尝试在 Julia 中使用带有结构作为参数的 C 函数,我调用了函数,但出现了问题。一个简单的例子如下:
在 C 中:
typedef struct {
int width;
int height;
int stride;
float* elements;
} Matriz;
是一个存储矩阵的简单结构,具有width、heigth、stride 和elements 字段
float GetElm(const Matriz A, int row, int col)
{
return (row < A.height && col < A.width ?
A.elements[row * A.stride + col] : 0);
}
是一个函数,它返回给定行和列的矩阵元素。
在 Julia 中:
immutable Matriz
width::Cint
height::Cint
stride::Cint
elements::Array{Float32,1}
end
M=Matriz(5,5,5,Array{Float32,1}(collect(0:24))) #creating a Matrix of 5x5
ccall((:GetElm,"path/to/dll"),Float32,(Matriz,Cint,Cint),M,0,1)
ccall 根据代码应该返回1.0,但是返回另一个值,是不是我做错了什么?
【问题讨论】: