mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-07 07:12:25 +01:00
Author:halw
Date:2012-12-14T00:21:39.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1207 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -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 <code>floor</code> 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 <code>my_floor</code> instead of <code>floor</code>. You could use the <code>alias</code> 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 <code>floor</code> 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 <code>my_floor</code> instead of <code>floor</code>. You could use the <code>alias</code> part of the external specification to state that the actual C function name differs from the Eiffel name, as shown below.
|
||||
|
||||
<code>
|
||||
my_floor (v: DOUBLE): DOUBLE
|
||||
@@ -44,3 +44,23 @@ In the <code>floor</code> example above, the Eiffel function has the same name a
|
||||
end
|
||||
</code>
|
||||
|
||||
|
||||
==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 <code>alias</code> 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 <code>my_floor</code> written as an inline external:
|
||||
|
||||
<code>
|
||||
my_floor (v: DOUBLE): DOUBLE
|
||||
-- Floor of `v'
|
||||
external
|
||||
"C inline use <math.h>"
|
||||
|
||||
alias
|
||||
"return floor($v)"
|
||||
end
|
||||
</code>
|
||||
|
||||
In the <code>alias</code> part you see a line of C code calling the library function <code>floor</code> and returning the result. The argument to the call to <code>floor</code> needs to be the argument to the Eiffel function <code>my_floor</code>. 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.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user