diff --git a/documentation/current/solutions/other-languages/eiffel-external-mechanism/interfacing-c-and-c.wiki b/documentation/current/solutions/other-languages/eiffel-external-mechanism/interfacing-c-and-c.wiki index 170f06b0..3133d894 100644 --- a/documentation/current/solutions/other-languages/eiffel-external-mechanism/interfacing-c-and-c.wiki +++ b/documentation/current/solutions/other-languages/eiffel-external-mechanism/interfacing-c-and-c.wiki @@ -32,7 +32,7 @@ The "use" part denotes provides a file name or list of file names. File names ca Alternatively, you could code the external as a verbatim string. This would make the percent signs unnecessary. -In the floor example above, the Eiffel function has the same name as the C function it targets. But that may not always be the case. It's possible that the C function name might conflict with a name already established in your class, or might conflict with Eiffel naming conventions. Suppose you wanted to call the Eiffel routine my_floor instead of floor. You could use the alias part of the external specification to state that the actual C function name differs from the Eiffel name, as shown below. +There's one more thing to note about using existing C functions. In the floor example above, the Eiffel function has the same name as the C function it targets. But that may not always be the case. It's possible that the C function name might conflict with a name already established in your class, or might conflict with Eiffel naming conventions. Suppose you wanted to call the Eiffel routine my_floor instead of floor. You could use the alias part of the external specification to state that the actual C function name differs from the Eiffel name, as shown below. my_floor (v: DOUBLE): DOUBLE @@ -44,3 +44,23 @@ In the floor example above, the Eiffel function has the same name a end + +==Inline externals== + +In addition to using an existing C function, you can, for both C and C++, create an '''inline''' external. The idea here is that you write the necessary C or C++ language within the definition of the external. In the case of inline externals the alias part is used to contain the inline code rather than a function name. Your inline C and C++ code can access the arguments of the external feature. Let's look at my_floor written as an inline external: + + + my_floor (v: DOUBLE): DOUBLE + -- Floor of `v' + external + "C inline use " + + alias + "return floor($v)" + end + + +In the alias part you see a line of C code calling the library function floor and returning the result. The argument to the call to floor needs to be the argument to the Eiffel function my_floor. To do this in the inline C code, the dollar sign ('$') precedes the argument name "v". So, the convention in inline externals is to use the dollar sign in C or C++ code to reference an argument of the Eiffel function. + + +