Next: , Previous: , Up: Foreign language interface   [Contents]

14.8 Adding foreign definitions

Definitions of foreign language entities (such as functions or global variables) may be included using a declaration of the form

:- pragma foreign_code("Lang", Code).

This declaration will have effects equivalent to including the specified Code in an automatically-generated source file of the specified programming language, in a place appropriate for definitions, and linking that source file with the Mercury program (after having compiled it with a compiler for the specified programming language, if appropriate).

Entities declared in ‘pragma foreign_code’ declarations are visible in ‘pragma foreign_proc’ declarations that specify the same foreign language and occur in the same Mercury module.