Julia - C结构中固定大小的数组

Mat*_*ord 5 c struct julia

我需要创建一个对应于具有固定大小数组的C结构的Julia类型:

struct cstruct {
    ...
    int arr[N] //N known at compile time
    ...
};
Run Code Online (Sandbox Code Playgroud)

我已经定义了与其他C结构相对应的Julia类型,其数组如下:

type  jstruct
    ...
    arr::Ptr{Cint}
    ...
end
Run Code Online (Sandbox Code Playgroud)

但据我了解,这只适用于arr 指针,而不是特定大小的数组.如何确保后续元素的偏移量arr在两种语言中保持不变?

Mat*_* B. 9

当您使用固定大小的数组(或使用数组hack)定义C结构时,数据将直接内联存储在该结构中.它不是指向另一个区域的指针.等效的Julia结构是:

type JStruct{N}
    arr::NTuple{N,Int}
end
Run Code Online (Sandbox Code Playgroud)

这将直接在结构中内联存储整数.