CECIL - Eiffel to C

array

This example shows how to create a C array from an existing Eiffel array.

After you have done the appropriate steps to compile the example, you will get a cecil.exe on windows, or cecil on Unix.

Launch the program and you will be prompted for 10 integers that will be inserted in an Eiffel array, it will then initialize the C array and display it.

A typical output will be: $ ./cecil This example create n array on the Eiffel side and print it on the C side Enter 10 integers: 1 2 3 4 5 6 7 8 9 10 Displaying from C @1 = 1 @2 = 2 @3 = 3 @4 = 4 @5 = 5 @6 = 6 @7 = 7 @8 = 8 @9 = 9 @10 = 10

object

This example shows the Eiffel memory management and all issues when passing an Eiffel object reference to C. In the example, you can edit the file root_class.e to modify the example: --give_to_c (o1) give_to_c_by_pointer ($o1) -- Choose the way you pass it When you choose the first possibility (commented by default), give_to_c will use the CECIL API eif_adopt to keep a reference on the Eiffel object. When you choose the second possibility, give_to_c_by_pointer will use the CECIL API eif_protect to keep a reference on the Eiffel object. Until forget_from_c is called from the C side, the object o1 will not be collected since we have protected it through the call to give_to_c or give_to_c_by_pointer. At the end after the object o1 is collected, we try to perform an operation on it which will fail with a call on void target exception. A typical output will be: $ cecil Creating o1 Object string is o1 Give it to C Losing reference to initial o1 from Eiffel Collecting... Display new o1: Object string is o2 Display o1 given to C: Object string is o1 Losing reference from C Losing reference from Eiffel Collecting... An Eiffel object of type OBJECT is collected Old o1 forgot from both C and Eiffel: Raise a Void exception.. cecil: system execution failed. Following is the set of recorded exceptions: ------------------------------------------------------------------------------- Class / Object Routine Nature of exception Effect ------------------------------------------------------------------------------- ROOT_CLASS make @26 display: <30068030> Feature call on void target. Fail ------------------------------------------------------------------------------- ROOT_CLASS make @26 <30068030> Routine failure. Fail ------------------------------------------------------------------------------- ROOT_CLASS root's creation <30068030> Routine failure. Exit ------------------------------------------------------------------------------- An Eiffel object of type OBJECT is collected

string

This example shows how to create a C string from an existing Eiffel string. After you have done the appropriate steps to compile the example, you will get a cecil.exe on windows, or cecil on Unix. Launch the program and you will be prompted for a string from Eiffel and a C string will be created and display. A typical output will be: $ cecil Enter a string to convert into a C string: Hello World! Here is the C string: Hello World!