Clang Edit Requirements

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.

Result code, RESULT_SUCCESS if successful.
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


Read the MCC 172 serial number.
function mcc172_serial(address::Integer)
	serial = Vector{UInt8}(undef, 9)  # initialize serial
	resultCode = ccall((:mcc172_serial, ""), 
	Cint, (UInt8, Ptr{Cchar}), address, serial)
	return unsafe_string(pointer(serial))

and the Clang function is:

function mcc172_serial(address, buffer)
    ccall((:mcc172_serial,, Cint, (UInt8, Ptr{Cchar}), address, buffer)

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.

1 Like

Clang.jl has no way of knowing that some arguments are really out-arguments and even if it did, it’s not clear that there is a general transformation to return values that would be useful. The point of clang.jl is to parse the headers and write the ccall for you. Any higher-level transformations are still manual.