Call a foreign-language function: Difference between revisions

no edit summary
m (Automated syntax highlighting fixup (second round - minor fixes))
No edit summary
Line 868:
duplicate
</pre>
 
=={{header|FutureBasic}}==
The C Standary Library doesn't include the strdup() function. In the code below, strdup has been declared, written and executed in C. FB allows users to pass-through and compile C code, and that's what been chosen for this example.
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
BeginCDeclaration
char *strdup(const char *src);
EndC
 
BeginCFunction
char *strdup(const char *src) {
char *dst = malloc(strlen (src) + 1); // Space for length plus nul
if (dst == NULL) return NULL; // No memory
strcpy(dst, src); // Copy the characters
return dst; // Return the new string
}
EndC
 
BeginCCode
NSLog( @"%s", strdup( "Hello, World!" ) );
EndC
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Hello, World!
</pre>
 
 
 
=={{header|Go}}==
Using cgo, part of the standard Go command set.
715

edits