Up Top       Prev External calls:      Next Generated C code


Cecil



Here is the information you need if you want to call any Eiffel features from C code. To call C functions/macros from Eiffel see the documentation about externals.

In order to call an Eiffel feature from C, you must use the -cecil <cecil_file> option with se-compile or compile_to_c. The <cecil_file> allows you to give the list of features you want to call from C. The corresponding stub routines will be automatically generated by SmallEiffel.
When the -cecil option is used, compile_to_c also produces an additional C heading file which includes the necessary C prototypes.

Your <cecil_file> must contain at least two lines. The first line is the name of the C heading file to be produced (it may be useful if you need to create a C library). Other lines have the following structure:

<c_name> <eiffel_type> <feature_name>

The <c_name> is the name of the C function defined by compile_to_c to wrap the Eiffel call. The pair <eiffel_type> <feature_name> gives the complete name of the Eiffel feature to call. For example:

IsEiffelStringEmpty STRING empty
STRINGitem STRING item
strgrtr STRING infix ">"
array_of_int_count ARRAY[INTEGER] count
X_f X f

Bear in mind that the <eiffel_type> must be active in your Eiffel program: if <eiffel_type> is ARRAY[INTEGER] for example, your Eiffel program has to create at least one ARRAY[INTEGER].

The name of the feature to call, <feature_name> may even be an infix or a prefix feature name. The syntax is the same as the one used in Eiffel source.

Since attributes are features, if is of course possible to access them with this mechanism.

A call to X_f in the C code is equivalent to a call to x.f in Eiffel, with x of type X or any descendant of X. Indeed, X_f takes care of late binding. This means that X_f can be called on any (Current) argument of type X or heir of X.

As <cecil_file> is parsed by the SmallEiffel parser, it may contain Eiffel comments.

Here is one example of a Cecil file (others can be found in the directories /usr/lib/smalleiffel/lib_show/cecil/example*):

-- The name of the include C file :
eiffel.h
-- The features you want to call from C :
array_of_animal_item	ARRAY[ANIMAL]	item
array_of_animal_lower	ARRAY[ANIMAL]	lower
array_of_animal_upper	ARRAY[ANIMAL]	upper
cry			ANIMAL		cry
string_to_external	STRING		to_external
People who tinker with the C code generated by SmallEiffel, not limiting themselves to the Cecil and/or external interfaces, should also read this page about the C code generated by SmallEiffel. Otherwise they might get into trouble.



Copyright © Dominique COLNET and Suzanne COLLIN - <colnet@loria.fr>
Last update: Monday December 7th, 1998, by OZ.



Up Top       Prev External calls:      Next Generated C code



This page was last changed for the Debian distribution of SmallEiffel by Oliver Elphick on 28th December 1998.