Calling C and Fortran
While Julia can rightfully claim to obviate the need to write some C or Fortran code, it is possible that you will need to interact with the existing C or Fortran shared libraries. Functions in such a library can be called directly by Julia, with no glue code, boilerplate code, or compilation needed. Because Julia's LLVM compiler generates native code, calling a C function from Julia has exactly the same overhead as calling the same function from C code itself. However, first, we need to know a few more things:
- For calling out to C, we need to work with pointer types; a native pointer
Ptr{T}
is nothing more than the memory address for a variable of typeT
. You can useCstring
if the value is null-terminated. - At this lower level, the term
primitive
 is also used.primitive
is a concrete type whose data consists of bits, such asInt8
,UInt8
,Int32
,Float64
,Bool
, andChar
. - To pass a string to C, it is converted to a contiguous byte array representation with the function
unsafe_string...