Book Image

Getting Started with Julia

By : Ivo Balbaert
Book Image

Getting Started with Julia

By: Ivo Balbaert

Overview of this book

Table of Contents (19 chapters)
Getting Started with Julia
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The Rationale for Julia
Index

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, or 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 type T

  • At this lower level, the term bitstype is also used; bitstype is a concrete type whose data consists of bits, such as Int8, Uint8, Int32, Float64, Bool, and Char

  • To pass a string to C, it is converted to a contiguous byte array representation with the function bytestring(); given Ptr to a C string, it returns a Julia...