-
Using the latest code fe798d9 and the following C declarations: typedef double mytype[1]; // no control over this typedef
mytype * get(void); // retrieve a mytype object
void f_bad(mytype a);
void f_good(double a[1]); The Julia code generated is: const mytype = NTuple{1, Cdouble}
function get()
ccall((:get, libtest), Ptr{mytype}, ())
end
function f_bad(a)
ccall((:f_bad, libtest), Cvoid, (mytype,), a)
end
function f_good(a)
ccall((:f_good, libtest), Cvoid, (Ptr{Cdouble},), a)
end In this case I am trying to understand why This seems to happen in the following code: Clang.jl/src/generator/translate.jl Lines 93 to 102 in fe798d9 I am wondering what C code the first Clang.jl/src/generator/codegen.jl Lines 26 to 27 in fe798d9 It sounds like it should apply for my example also? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
If
In C, using const array type as function parameter types does not add any special restriction(e.g. the size) than a naive pointer type, the C compiler just does the decay implicitly, so here we do the same thing in Julia.
Yes, the current behavior is a bug, thanks for catching this! I need to do a deeper check on that line, like if the type is a typedef, do the same check on the underlying type as well. The expected result would be:
Note that, to use this function, |
Beta Was this translation helpful? Give feedback.
If
mytype
is used as a type of a field member of a struct, it has to be a stack-allocatedNTuple
. If not, the layout of that struct will be incompatible with the one in C.In C, using const array type as function parameter types does not add any special restriction(e.g. the size) than a naive pointer type, the C compiler just does the decay implicitly, so here we do the same thing in Julia.