Version 1.4 of ais/ai-00320.txt

Unformatted version of ais/ai-00320.txt version 1.4
Other versions for file ais/ai-00320.txt

!standard B.1 (49)          04-11-09 AI95-00320/04
!class binding interpretation 03-01-02
!status Amendment 200Y 04-07-02
!status ARG Approved 8-0-0 04-06-17
!status work item 03-01-02
!status received 03-01-02
!qualifier Omission
!priority Low
!difficulty Easy
!subject Violating Ada semantics with an interfacing pragma
!summary
The note B.1(49) ("an interfacing pragma might result in an effect that violates Ada semantics.") is correct.
!question
The minutes of the October 2002 ARG meeting say:
If you violate any Ada semantic requirements in C (by stomping on memory, for instance), all bets are off.
This is clearly a requirement, as the Ada compiler has no control over what the foreign language code can do.
However, the only mention of this in the Standard is a note, B.1(49):
An interfacing pragma might result in an effect that violates Ada semantics.
It appears that the standard needs a normative statement to this effect.
!recommendation
(See Wording.)
!wording
Add after B.1(38):
Erroneous Execution
It is the programmer's responsibility to ensure that the use of interfacing pragmas does not violate Ada semantics; otherwise, program execution is erroneous.
!discussion
This wording includes pragma Import, Export, and Convention for all conventions, including Ada. That's necessary as Convention only specifies the calling convention, while the body of an imported routine (or the caller of an exported routine) may be written in any language. And that other language could easily violate Ada semantics.
Note the even calling Ada code with a foreign convention may violate Ada semantics, a foreign convention may not include needed support for Ada semantics. Imagine an implementation that passes the current innermost exception handler in a specific register. The C calling convention would most likely not pass or save that register, and thus exceptions could not propagate through a C convention call, even if both the caller and called routine are written in Ada. This seems like a reasonable implementation; thus it is possible to violate Ada semantics with just a Convention.
The wording makes it the programmer's (and not the implementer's) responsibility to use interfacing wisely and safely.
!corrigendum B.1(38)
Insert after the paragraph:
Notwithstanding what this International Standard says elsewhere, the elaboration of a declaration denoted by the local_name of a pragma Import does not create the entity. Such an elaboration has no other effect than to allow the defining name to denote the external entity.
the new paragraph:
Erroneous Execution
It is the programmer's responsibility to ensure that the use of interfacing pragmas does not violate Ada semantics; otherwise, program execution is erroneous.
!ACATS test
We can't usefully test if a compiler does this, as it is a permission, not a requirement.
!appendix

****************************************************************

Questions? Ask the ACAA Technical Agent