Suppose I have:
%{^
uint8 funA(uint8* data) { return(0); } // Some array operation happens in
here
uint8_t data[256]; // Some place to hold data for funA to work with
%}
// A macro to access the data as an arrayref
macdef my_data =
$extval(arrayref(uint8, 256),“data”)
// And ATS version of the function
fun funA_ (cPtr0(uint8)) : uint8 = “mac#funA”
val v = funA_(ptr2cptr(my_data)) // The compiler does not like this
// Get a value for use
val v’ = my_data[0]
Given above, ptr2cptr does not work on the array ref. What is the proper
way to pass my_data into the C call?
The assumption here is that funA will never go beyond 256 values into the
passed in data. This is because of a hardware limitation where a count is a
byte. So it is safe. So if ATS deals with arrayref(uint8, 256), things
can’t get into trouble. But I need to pass the ATS array into C to get
something in hardware done.
A secondary question.
fun funB(val: arrayref(uint8,256)):uint8 =
val v = funB(my_data)
Is this the proper way to define a function that takes the arrayref? Or is
there some signature with and ‘&’ that does this like for a var?