by Manu (modified: 2007 Mar 01)

What is the difference between EIF_REFERENCE and EIF_OBJECT?

EIF_REFERENCE is a direct reference to an Eiffel object. This reference is only valid until the next GC cycle which will move objects around and make some EIF_REFERENCE values invalid if the GC does not update them. Storing the value of the EIF_REFERENCE is therefore unsafe.

EIF_OBJECT on the other hand is a protected reference to an Eiffel object and won't change even after a GC cycle. To access its EIF_REFERENCE, simply use eif_access.

What should be used?

If you are building an external taking an Eiffel object, I recommend using EIF_REFERENCE rather than EIF_OBJECT since it will be faster (no protection is performed by the compiler while generating the code). But only do that if your C external does not perform any callbacks. Otherwise you have to use EIF_OBJECT.


Knowing when to use an EIF_REFERENCE or an EIF_OBJECT is critical to the reliability of your application when interfacing to C or CECIL.

Want to know which one is used the most, check out: Google Fight Result.