Call a foreign-language function: Difference between revisions

m
added whitespace before the TOC (table of contents), added a ;Task: (bold) header, added other whitespace to the task's preamble.
m (→‎{{header|Perl 6}}: use native types)
m (added whitespace before the TOC (table of contents), added a ;Task: (bold) header, added other whitespace to the task's preamble.)
Line 1:
{{task|Programming environment operations}}
 
;Task:
Show how a [[Foreign function interface|foreign language function]] can be called from the language.
 
 
As an example, consider calling functions defined in the [[C]] language. Create a string containing "Hello World!" of the string type typical to the language. Pass the string content to [[C]]'s <code>strdup</code>. The content can be copied if necessary. Get the result from <code>strdup</code> and print it using language means. Do not forget to free the result of <code>strdup</code> (allocated in the heap).
 
 
;Notes:
* It is not mandated if the [[C]] run-time library is to be loaded statically or dynamically. You are free to use either way.
* [[C++]] and [[C]] solutions can take some other language to communicate with.
* It is ''not'' mandatory to use <code>strdup</code>, especially if the foreign function interface being demonstrated makes that uninformative.
 
 
;See also:
* &nbsp; [[Use another language to call a function]]
<br><br>
 
=={{header|ALGOL 68}}==
The designers of Algol 68 made it extremely hard to incorporate code written in other languages. To be fair, this was a long time ago when such considerations weren't thought important and one should be careful to apply Hanlon's razor.