I did some work on making a Julia interface for the MCC172. It has a c language library which I wrapped into Julia code. Then I came across Clang and thought I would try it and compare. For the simpler functions I get identical results. However when C returns information into one of the function calling names, my function and the Clang function differ.
Take for example the simple function to read the serial number of the board where the help states:
int mcc172_serial(uint8_t address, char * buffer)
Read the MCC 172 serial number.
Return
Result code, RESULT_SUCCESS if successful.
Parameters
address: The board address (0 - 7). Board must already be opened.
buffer: Pass a user-allocated buffer pointer to receive the serial number as a string. The buffer must be at least 9 characters in length.
The function I wrote is
"""
mcc172_serial(address::Integer)
Read the MCC 172 serial number.
"""
function mcc172_serial(address::Integer)
serial = Vector{UInt8}(undef, 9) # initialize serial
resultCode = ccall((:mcc172_serial, "libdaqhats.so"),
Cint, (UInt8, Ptr{Cchar}), address, serial)
printError(resultCode)
return unsafe_string(pointer(serial))
end
and the Clang function is:
function mcc172_serial(address, buffer)
ccall((:mcc172_serial, libdaqhats.so), Cint, (UInt8, Ptr{Cchar}), address, buffer)
end
Here the item returned by the ccall is the buffer with the serial number. It seems the Julia function is trying to return it the same way. However Julia functions return information as the last line with the optional return keyword. But the Clang Julia function is trying to return this information as a C-function would. Is this a shortcoming with Clang or is there an option in Clang that will rectify this, or does Julia have some capability that I am not aware of.