1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>Problem Example</TITLE>
<SCRIPT type="text/javascript" src="../../doc/erlresolvelinks.js">
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif"></A>
</CENTER>
<A NAME="3"><!-- Empty --></A>
<H2>3 Problem Example</H2>
<A NAME="3.1"><!-- Empty --></A>
<H3>3.1 Description</H3>
<P>A common interoperability situation is when there exists a piece of code solving some complex problem, and we would like to incorporate this piece of code in our Erlang program. Suppose for example we have the following C functions that we would like to be able to call from Erlang.
<PRE>
/* complex.c */
int foo(int x) {
return x+1;
}
int bar(int y) {
return y*2;
}
</PRE>
<P>(For the sake of keeping the example as simple as possible, the functions are not very complicated in this case).
<P>Preferably we would like to able to call <CODE>foo</CODE> and <CODE>bar</CODE> without having to bother about them actually being C functions.
<PRE>
% Erlang code
...
Res = complex:foo(X),
...
</PRE>
<P>The communication with C is hidden in the implementation of <CODE>complex.erl</CODE>. In the following chapters it is shown how this module can be implemented using the different interoperability mechanisms.<CENTER>
<HR>
<SMALL>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|