1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Interfacing Pragmas</TITLE>
<META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
<META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
<STYLE type="text/css">
DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
TT {font-family: "Courier New", monospace}
DT {display: compact}
DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Index {font-family: "Times New Roman", Times, serif}
DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left: 10.0em; margin-bottom: 0.6em}
DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 15.0em; margin-bottom: 0.6em}
UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
DD.Hanging {margin-left: 6.0em}
DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.IndentedHanging {margin-left: 2.0em}
DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.HangingInBulleted {margin-left: 4.0em}
DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallHanging {margin-left: 7.5em}
DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallIndentedHanging {margin-left: 2.0em}
DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallHangingInBulleted {margin-left: 5.0em}
DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.Enumerated {margin-left: 2.0em}
DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallEnumerated {margin-left: 2.5em}
DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-B.html">Previous</A> <A HREF="AA-B-2.html">Next</A></P>
<HR>
<H1> B.1 Interfacing Pragmas</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> A <FONT FACE="Arial, Helvetica">pragma</FONT>
Import is used to import an entity defined in a foreign language into
an Ada program, thus allowing a foreign-language subprogram to be called
from Ada, or a foreign-language variable to be accessed from Ada. In
contrast, a <FONT FACE="Arial, Helvetica">pragma</FONT> Export is used
to export an Ada entity to a foreign language, thus allowing an Ada subprogram
to be called from a foreign language, or an Ada object to be accessed
from a foreign language. The <FONT FACE="Arial, Helvetica">pragma</FONT>s
Import and Export are intended primarily for objects and subprograms,
although implementations are allowed to support other entities.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="Normal"> A <FONT FACE="Arial, Helvetica">pragma</FONT>
Convention is used to specify that an Ada entity should use the conventions
of another language. It is intended primarily for types and ``callback''
subprograms. For example, ``<B>pragma</B> Convention(Fortran, Matrix);''
implies that Matrix should be represented according to the conventions
of the supported Fortran implementation, namely column-major order.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="Normal"> A <FONT FACE="Arial, Helvetica">pragma</FONT>
Linker_Options is used to specify the system linker parameters needed
when a given compilation unit is included in a partition.</DIV>
<H4 ALIGN=CENTER>Syntax</H4>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="SyntaxIndented" Style="margin-bottom: 0.2em"><A NAME="I6284"></A><A NAME="I6285"></A><A NAME="I6286"></A><A NAME="I6287"></A><A NAME="I6288"></A><A NAME="I6289"></A><A NAME="I6290"></A><A NAME="I6291"></A>An
<I>interfacing pragma</I> is a representation <FONT FACE="Arial, Helvetica">pragma</FONT>
that is one of the <FONT FACE="Arial, Helvetica">pragma</FONT>s Import,
Export, or Convention. Their forms, together with that of the related
<FONT FACE="Arial, Helvetica">pragma</FONT> Linker_Options, are as follows:
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="SyntaxIndented"> <B>pragma</B> <A NAME="I6292"></A>Import(<BR>
[Convention =>] <I>convention_</I><A NAME="I6293"></A><FONT FACE="Arial, Helvetica">identifier</FONT>,
[Entity =>] <A NAME="I6294"></A><FONT FACE="Arial, Helvetica">local_name</FONT><BR>
[, [External_Name =>] <I>string_</I><A NAME="I6295"></A><FONT FACE="Arial, Helvetica">expression</FONT>]
[, [Link_Name =>] <I>string_</I><A NAME="I6296"></A><FONT FACE="Arial, Helvetica">expression</FONT>]);</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="SyntaxIndented"> <B>pragma</B> <A NAME="I6297"></A>Export(<BR>
[Convention =>] <I>convention_</I><A NAME="I6298"></A><FONT FACE="Arial, Helvetica">identifier</FONT>,
[Entity =>] <A NAME="I6299"></A><FONT FACE="Arial, Helvetica">local_name</FONT><BR>
[, [External_Name =>] <I>string_</I><A NAME="I6300"></A><FONT FACE="Arial, Helvetica">expression</FONT>]
[, [Link_Name =>] <I>string_</I><A NAME="I6301"></A><FONT FACE="Arial, Helvetica">expression</FONT>]);</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="SyntaxIndented"> <B>pragma</B> <A NAME="I6302"></A>Convention([Convention
=>] <I>convention_</I><A NAME="I6303"></A><FONT FACE="Arial, Helvetica">identifier</FONT>,[Entity
=>] <A NAME="I6304"></A><FONT FACE="Arial, Helvetica">local_name</FONT>);</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="SyntaxIndented"> <B>pragma</B> <A NAME="I6305"></A>Linker_Options(<I>string_</I><A NAME="I6306"></A><FONT FACE="Arial, Helvetica">expression</FONT>);</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="SyntaxIndented">A <FONT FACE="Arial, Helvetica">pragma</FONT>
Linker_Options is allowed only at the place of a <FONT FACE="Arial, Helvetica">declarative_item</FONT>.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.1/1</FONT></DIV>
<DIV Class="SyntaxIndented">{<I><A HREF="defect1.html#8652/0058">8652/0058</A></I>}
<U>For <FONT FACE="Arial, Helvetica">pragma</FONT>s Import and Export,
the argument for Link_Name shall not be given without the <FONT FACE="Arial, Helvetica">pragma_argument_identifier</FONT>
unless the argument for External_Name is given.</U> </DIV>
<H4 ALIGN=CENTER>Name Resolution Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Normal"> <A NAME="I6307"></A>The expected type for a <I>string_</I><A NAME="I6308"></A><FONT FACE="Arial, Helvetica">expression</FONT>
in an interfacing pragma or in pragma Linker_Options is String. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>There is
no language-defined support for external or link names of type Wide_String,
or of other string types. Implementations may, of course, have additional
pragmas for that purpose. Note that allowing both String and Wide_String
in the same <FONT FACE="Arial, Helvetica">pragma</FONT> would cause ambiguities.
</FONT></DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal"> <A NAME="I6309"></A>The <I>convention_</I><FONT FACE="Arial, Helvetica">identifier</FONT>
of an interfacing pragma shall be the name of a <I>convention</I>. The
convention names are implementation defined, except for certain language-defined
ones, such as Ada and Intrinsic, as explained in <A HREF="AA-6-3-1.html">6.3.1</A>,
``<A HREF="AA-6-3-1.html">Conformance Rules</A>''. [Additional convention
names generally represent the calling conventions of foreign languages,
language implementations, or specific run-time models.] <A NAME="I6310"></A>The
convention of a callable entity is its <I>calling convention</I>. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B>Implementation-defined
convention names.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>We considered
representing the convention names using an enumeration type declared
in System. Then, <I>convention_</I><FONT FACE="Arial, Helvetica">identifier</FONT>
would be changed to <I>convention_</I><FONT FACE="Arial, Helvetica">name</FONT>,
and we would make its expected type be the enumeration type. We didn't
do this because it seems to introduce extra complexity, and because the
list of available languages is better represented as the list of children
of package Interfaces -- a more open-ended sort of list. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I6311"></A>If
<I>L</I> is a <I>convention_</I><FONT FACE="Arial, Helvetica">identifier</FONT>
for a language, then a type T is said to be <I>compatible with convention
L</I>, (alternatively, is said to be an <I>L-compatible type</I>) if
any of the following conditions are met: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>T is declared in a language interface package corresponding
to <I>L</I> and is defined to be <I>L</I>-compatible (see <A HREF="AA-B-3.html">B.3</A>,
<A HREF="AA-B-3-1.html">B.3.1</A>, <A HREF="AA-B-3-2.html">B.3.2</A>,
<A HREF="AA-B-4.html">B.4</A>, <A HREF="AA-B-5.html">B.5</A>),</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC><A NAME="I6312"></A>Convention <I>L</I> has been specified
for T in a <FONT FACE="Arial, Helvetica">pragma</FONT> Convention, and
T is <I>eligible for convention L</I>; that is: </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<UL Class="NestedBulleted"><LI TYPE=DISC>T is an array type with either an unconstrained or statically-constrained
first subtype, and its component type is <I>L</I>-compatible,</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<UL Class="NestedBulleted"><LI TYPE=DISC>T is a record type that has no discriminants and that only
has components with statically-constrained subtypes, and each component
type is <I>L</I>-compatible,</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<UL Class="NestedBulleted"><LI TYPE=DISC>T is an access-to-object type, and its designated type
is <I>L</I>-compatible,</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<UL Class="NestedBulleted"><LI TYPE=DISC>T is an access-to-subprogram type, and its designated profile's
parameter and result types are all <I>L</I>-compatible. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>T is derived from an <I>L</I>-compatible type,</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>The implementation permits T as an <I>L</I>-compatible
type. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>20.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>For example,
an implementation might permit Integer as a C-compatible type, though
the C type to which it corresponds might be different in different environments.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<DIV Class="Normal"> If <FONT FACE="Arial, Helvetica">pragma</FONT>
Convention applies to a type, then the type shall either be compatible
with or eligible for the convention specified in the pragma. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>If a type
is derived from an <I>L</I>-compatible type, the derived type is by default
<I>L</I>-compatible, but it is also permitted to specify pragma Convention
for the derived type.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>It is permitted to specify pragma
Convention for an incomplete type, but in the complete declaration each
component must be <I>L</I>-compatible.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>If each component of a record
type is <I>L</I>-compatible, then the record type itself is only <I>L</I>-compatible
if it has a pragma Convention. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>22</FONT></DIV>
<DIV Class="Normal"> A <FONT FACE="Arial, Helvetica">pragma</FONT>
Import shall be the completion of a declaration. <A NAME="I6313"></A>Notwithstanding
any rule to the contrary, a <FONT FACE="Arial, Helvetica">pragma</FONT>
Import may serve as the completion of any kind of (explicit) declaration
if supported by an implementation for that kind of declaration. If a
completion is a <FONT FACE="Arial, Helvetica">pragma</FONT> Import, then
it shall appear in the same <FONT FACE="Arial, Helvetica">declarative_part</FONT>,
<FONT FACE="Arial, Helvetica">package_specification</FONT>, <FONT FACE="Arial, Helvetica">task_definition</FONT>
or <FONT FACE="Arial, Helvetica">protected_definition</FONT> as the declaration.
For a library unit, it shall appear in the same <FONT FACE="Arial, Helvetica">compilation</FONT>,
before any subsequent <FONT FACE="Arial, Helvetica">compilation_unit</FONT>s
other than <FONT FACE="Arial, Helvetica">pragma</FONT>s. If the <FONT FACE="Arial, Helvetica">local_name</FONT>
denotes more than one entity, then the <FONT FACE="Arial, Helvetica">pragma</FONT>
Import is the completion of all of them. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>22.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>For declarations
of deferred constants and subprograms, we mention pragma Import explicitly
as a possible completion. For other declarations that require completions,
we ignore the possibility of pragma Import. Nevertheless, if an implementation
chooses to allow a <FONT FACE="Arial, Helvetica">pragma</FONT> Import
to complete the declaration of a task, protected type, incomplete type,
private type, etc., it may do so, and the normal completion is then not
allowed for that declaration. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>23</FONT></DIV>
<DIV Class="Normal"> <A NAME="I6314"></A> <A NAME="I6315"></A>An entity
specified as the Entity argument to a <FONT FACE="Arial, Helvetica">pragma</FONT>
Import (or <FONT FACE="Arial, Helvetica">pragma</FONT> Export) is said
to be <I>imported</I> (respectively, <I>exported</I>).</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24</FONT></DIV>
<DIV Class="Normal"> The declaration of an imported object shall not
include an explicit initialization expression. [Default initializations
are not performed.] </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Proof: </B>This follows from
the ``Notwithstanding ...'' wording in the Dynamics Semantics paragraphs
below. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>25</FONT></DIV>
<DIV Class="Normal"> The type of an imported or exported object shall
be compatible with the convention specified in the corresponding <FONT FACE="Arial, Helvetica">pragma</FONT>.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>25.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This implies,
for example, that importing an Integer object might be illegal, whereas
importing an object of type Interfaces.C.int would be permitted. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26</FONT></DIV>
<DIV Class="Normal"> For an imported or exported subprogram, the result
and parameter types shall each be compatible with the convention specified
in the corresponding pragma.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27</FONT></DIV>
<DIV Class="Normal"> The external name and link name <I>string</I>_<FONT FACE="Arial, Helvetica">expression</FONT>s
of a <FONT FACE="Arial, Helvetica">pragma</FONT> Import or Export, and
the <I>string</I>_<FONT FACE="Arial, Helvetica">expression</FONT> of
a <FONT FACE="Arial, Helvetica">pragma</FONT> Linker_Options, shall be
static. </DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>28</FONT></DIV>
<DIV Class="Normal"> <A NAME="I6316"></A><A NAME="I6317"></A><A NAME="I6318"></A><A NAME="I6319"></A><A NAME="I6320"></A><A NAME="I6321"></A><A NAME="I6322"></A><A NAME="I6323"></A>Import,
Export, and Convention <FONT FACE="Arial, Helvetica">pragma</FONT>s are
representation pragmas that specify the <I>convention</I> aspect of representation.
<A NAME="I6324"></A><A NAME="I6325"></A><A NAME="I6326"></A><A NAME="I6327"></A>In
addition, Import and Export <FONT FACE="Arial, Helvetica">pragma</FONT>s
specify the <I>imported</I> and <I>exported</I> aspects of representation,
respectively.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29</FONT></DIV>
<DIV Class="Normal"> <A NAME="I6328"></A><A NAME="I6329"></A><A NAME="I6330"></A><A NAME="I6331"></A><A NAME="I6332"></A><A NAME="I6333"></A>An
interfacing pragma is a program unit pragma when applied to a program
unit (see <A HREF="AA-10-1-5.html">10.1.5</A>).</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>30</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> An interfacing
pragma defines the convention of the entity denoted by the <FONT FACE="Arial, Helvetica">local_name</FONT>.
The convention represents the calling convention or representation convention
of the entity. For an access-to-subprogram type, it represents the calling
convention of designated subprograms. In addition: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>31</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>A <FONT FACE="Arial, Helvetica">pragma</FONT> Import specifies
that the entity is defined externally (that is, outside the Ada program).</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>32</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>A <FONT FACE="Arial, Helvetica">pragma</FONT> Export specifies
that the entity is used externally.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>33</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>A <FONT FACE="Arial, Helvetica">pragma</FONT> Import or
Export optionally specifies an entity's external name, link name, or
both. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>34</FONT></DIV>
<DIV Class="Normal"> <A NAME="I6334"></A>An <I>external name</I> is
a string value for the name used by a foreign language program either
for an entity that an Ada program imports, or for referring to an entity
that an Ada program exports.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35</FONT></DIV>
<DIV Class="Normal"> <A NAME="I6335"></A>A <I>link name</I> is a string
value for the name of an exported or imported entity, based on the conventions
of the foreign language's compiler in interfacing with the system's linker
tool.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36</FONT></DIV>
<DIV Class="Normal"> The meaning of link names is implementation defined.
If neither a link name nor the Address attribute of an imported or exported
entity is specified, then a link name is chosen in an implementation-defined
manner, based on the external name if one is specified. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B>The
meaning of link names.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>For example,
an implementation might always prepend "_", and then pass it
to the system linker. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B>The
manner of choosing link names when neither the link name nor the address
of an imported or exported entity is specified.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Normally,
this will be the entity's defining name, or some simple transformation
thereof. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37</FONT></DIV>
<DIV Class="Normal"> Pragma Linker_Options has the effect of passing
its string argument as a parameter to the system linker (if one exists),
if the immediately enclosing compilation unit is included in the partition
being linked. The interpretation of the string argument, and the way
in which the string arguments from multiple Linker_Options pragmas are
combined, is implementation defined. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B>The
effect of pragma Linker_Options.</FONT></DIV>
<H4 ALIGN=CENTER>Dynamic Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>38</FONT></DIV>
<DIV Class="Normal"> <A NAME="I6336"></A><A NAME="I6337"></A>Notwithstanding
what this International Standard says elsewhere, the elaboration of a
declaration denoted by the <FONT FACE="Arial, Helvetica">local_name</FONT>
of a <FONT FACE="Arial, Helvetica">pragma</FONT> Import does not create
the entity. Such an elaboration has no other effect than to allow the
defining name to denote the external entity. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>38.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This implies
that default initializations are skipped. (Explicit initializations are
illegal.) For example, an imported access object is <I>not</I> initialized
to <B>null</B>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>38.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that the <FONT FACE="Arial, Helvetica">local_name</FONT>
in a <FONT FACE="Arial, Helvetica">pragma</FONT> Import might denote
more than one declaration; in that case, the entity of all of those declarations
will be the external entity. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>38.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>This ``notwithstanding''
wording is better than saying ``unless named by a <FONT FACE="Arial, Helvetica">pragma</FONT>
Import'' on every definition of elaboration. It says we recognize the
contradiction, and this rule takes precedence. </FONT></DIV>
<H4 ALIGN=CENTER>Implementation Advice</H4>
<DIV Class="Paranum"><FONT SIZE=-2>39</FONT></DIV>
<DIV Class="Normal"> If an implementation supports pragma Export to
a given language, then it should also allow the main subprogram to be
written in that language. It should support some mechanism for invoking
the elaboration of the Ada library units included in the system, and
for invoking the finalization of the environment task. On typical systems,
the recommended mechanism is to provide two subprograms whose link names
are "adainit" and "adafinal". Adainit should contain
the elaboration code for library units. Adafinal should contain the finalization
code. These subprograms should have no effect the second and subsequent
time they are called. <U><A NAME="I6338"></A><A NAME="I6339"></A><A NAME="I6340"></A><A NAME="I6341"></A></U></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>39.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>For example,
if the main subprogram is written in C, it can call adainit before the
first call to an Ada subprogram, and adafinal after the last.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>40</FONT></DIV>
<DIV Class="Normal"> Automatic elaboration of preelaborated packages
should be provided when <FONT FACE="Arial, Helvetica">pragma</FONT> Export
is supported.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>41</FONT></DIV>
<DIV Class="Normal"> For each supported convention <I>L</I> other
than Intrinsic, an implementation should support Import and Export <FONT FACE="Arial, Helvetica">pragma</FONT>s
for objects of <I>L</I>-compatible types and for subprograms, and <FONT FACE="Arial, Helvetica">pragma</FONT>
Convention for <I>L</I>-eligible types and for subprograms, presuming
the other language has corresponding features. <FONT FACE="Arial, Helvetica">Pragma</FONT>
Convention need not be supported for scalar types. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>41.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Pragma Convention
is not necessary for scalar types, since the language interface packages
declare scalar types corresponding to those provided by the respective
foreign languages. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>41.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>If
an implementation supports interfacing to C++, it should do so via the
convention identifier C_Plus_Plus (in additional to any C++-implementation-specific
ones). </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>41.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>The reason for
giving the advice about C++ is to encourage uniformity among implementations,
given that the name of the language is not syntactically legal as an
<FONT FACE="Arial, Helvetica">identifier</FONT>. We place this advice
in the AARM, rather than the RM95 proper, because (as of this writing)
C++ is not an international standard, and we don't want to refer to a
such a language from an international standard. </FONT></DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>42</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>1 Implementations may place
restrictions on interfacing pragmas; for example, requiring each exported
entity to be declared at the library level. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>42.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Proof: </B>Arbitrary restrictions
are allowed by <A HREF="AA-13-1.html">13.1</A>. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>42.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Such a restriction
might be to disallow them altogether. Alternatively, the implementation
might allow them only for certain kinds of entities, or only for certain
conventions. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>43</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>2 A <FONT FACE="Arial, Helvetica">pragma</FONT>
Import specifies the conventions for accessing external entities. It
is possible that the actual entity is written in assembly language, but
reflects the conventions of a particular language. For example, <B>pragma</B>
Import(Ada, ...) can be used to interface to an assembly language routine
that obeys the Ada compiler's calling conventions.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>3 To obtain ``call-back''
to an Ada subprogram from a foreign language environment, <B>pragma</B>
Convention should be specified both for the access-to-subprogram type
and the specific subprogram(s) to which 'Access is applied.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>45</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>4 It is illegal to specify
more than one of Import, Export, or Convention for a given entity.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>46</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>5 The <FONT FACE="Arial, Helvetica">local_name</FONT>
in an interfacing pragma can denote more than one entity in the case
of overloading. Such a <FONT FACE="Arial, Helvetica">pragma</FONT> applies
to all of the denoted entities.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>47</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>6 See also <A HREF="AA-13-8.html">13.8</A>,
``<A HREF="AA-13-8.html">Machine Code Insertions</A>''. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>47.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>The Intrinsic
convention (see <A HREF="AA-6-3-1.html">6.3.1</A>) implies that the entity
is somehow ``built in'' to the implementation. Thus, it generally does
not make sense for users to specify Intrinsic in a <FONT FACE="Arial, Helvetica">pragma</FONT>
Import. The intention is that only implementations will specify Intrinsic
in a <FONT FACE="Arial, Helvetica">pragma</FONT> Import. The language
also defines certain subprograms to be Intrinsic. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>47.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>There are many
imaginable interfacing pragmas that don't make any sense. For example,
setting the Convention of a protected procedure to Ada is probably wrong.
Rather than enumerating all such cases, however, we leave it up to implementations
to decide what is sensible. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>48</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>7 If both External_Name and
Link_Name are specified for an Import or Export pragma, then the External_Name
is ignored.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>49</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>8 An interfacing pragma might
result in an effect that violates Ada semantics. </FONT></DIV>
<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>50</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <I>Example of interfacing
pragmas:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>51</FONT></DIV>
<DIV Class="Examples"><TT><B>package</B> Fortran_Library <B>is</B><BR>
<B>function</B> Sqrt (X : Float) <B>return</B> Float;<BR>
<B>function</B> Exp (X : Float) <B>return</B> Float;<BR>
<B>private</B><BR>
<B>pragma</B> Import(Fortran, Sqrt);<BR>
<B>pragma</B> Import(Fortran, Exp);<BR>
<B>end</B> Fortran_Library;</TT></DIV>
<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>51.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I6342"></A>Interfacing
pragmas are new to Ada 95. Pragma Import replaces Ada 83's pragma Interface.
Existing implementations can continue to support pragma Interface for
upward compatibility. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-B.html">Previous</A> <A HREF="AA-B-2.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|