Interfacing With C
The purpose of this exercise is to write a minimalistic interface to C code.
Question 1
Modify the functions in ada_float_maths.ads
so that they
are exported to C as float ada_cos(float)
and float ada_sin(float)
.
Question 2
Modify the functions in compute_c/compute.c
so that they call the
ada_sin
and ada_cos
functions.
NB: If you’re not comfortable using C you can skip this question by copying the answer source from the solution directly.
Question 3
In solar_system.adb
, import Compute_X
and Compute_Y
from
the C symbols compute_x
and compute_y
; and use them to update the position
of the bodies.
Question 4
Make it compile and run, there is a last element of surprise.
If you are stuck you can use the following tips, piecewise.
Tip: Multi-language projects are harder to build, namely the dependency tree is not automatically solved unlike Ada.
Tip 2: You are building a piece of Ada calling C calling Ada, and the compiler
is lazy: it will only compile what is with
Tip 3: Since C has implicit dependencies, it never with
any package. And especially
the Ada_Float_Math
package.