Jump to content

Ada Programming/Pragmas/Export

From Wikibooks, open books for an open world

Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.

Summary

[edit | edit source]

The pragma Export directs the compiler to make available subprograms or data objects written in Ada to foreign computer languages. If a subprogram is exported, it is compiled with conventions expected by the foreign language. For example, if a subprogram is being exported to C, record types declared in the subprogram are compiled the same as C-style structs.

The set of supported foreign languages depends on the compiler implementation. Typically C, C++, Cobol, and Fortran are supported.

Example

[edit | edit source]
/* C file */
int main() { 
  int My_Int;  
  adainit();   
  /* Zoiks! C is using an Ada function! */
  My_Int = My_Ada_Function();
  adafinal();
  return 0;
}
-- Ada File
function My_Ada_Function return Integer is begin
  return 1;
end My_Ada_Function;
pragma Export
(Convention    => C,
 Entity        => My_Ada_Function,
 External_Name => "My_Ada_Function" );

See also

[edit | edit source]

Wikibook

[edit | edit source]