Previous Contents Next

Introduction

Developing programs in a given language very often requires one to integrate libraries written in other languages. The two main reasons for this are: A program then becomes an assembly of software components written in various languages, where each component has been written in the language most appropriate for the part of the problem it addresses. Those software components interoperate by exchanging values and requesting computations.

The Objective CAML language offers such a mechanism for interoperability with the C language. This mechanism allows Objective CAML code to call C functions with Caml-provided arguments, and to get back the result of the computation in Objective CAML. The converse is also possible: a C program can trigger an Objective CAML computation, then work on its result.

The choice of C as interoperability language is justified by the following reasons: The C language can therefore be viewed as the esperanto of programming languages.

Cooperation between C and Objective CAML raises a number of difficulties that we review below. Programs written in Objective CAML benefit from the safety of static typing and automatic memory management. This safety must not be compromised by improper use of C libraries and interfacing with other languages through C. The programmer must therefore adhere to rather strict rules to ensure that both languages coexist peacefully.


Previous Contents Next