From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d3447e1f384e2115,start X-Google-Attributes: gid103376,public From: cgreen@yosemite.atc.com (Christopher Green) Subject: Placement of pragma Convention Date: 1997/06/20 Message-ID: <5oervk$g07@newshub.atmnet.net>#1/1 X-Deja-AN: 251422384 Organization: Advanced Technology Center, Laguna Hills, CA Newsgroups: comp.lang.ada Date: 1997-06-20T00:00:00+00:00 List-Id: I have a question concerning the correct placement of pragma Convention; in particular, whether GNAT and other Ada 95 compilers are properly inter- preting the applicable rules. Given the following code: package Callbacks is procedure OrdinaryProc; end Callbacks; package body Callbacks is procedure OrdinaryProc is begin null; end OrdinaryProc; procedure CallbackProc is begin null; end CallbackProc; pragma Convention (C, CallbackProc); end Callbacks; I get the following different results when it is compiled on different Ada 95 compilers. All compilers are self-hosted on a SPARC/Solaris 2.5 host. Apex 2.2.3A gives no errors and no warnings. ObjectAda V7.1 gives no errors and no warnings. GNAT 3.09 gives the following error: callbacks.adb:12:05: pragma "Convention" requires separate spec and must come before body It would appear to me that the Apex and ObjectAda compilers are correct and the GNAT compiler is incorrect, at least by the following reasoning: B.1(4): An interfacing pragma is a representation pragma that is one of the pragmas Import, Export, or Convention... B.1(30): An interfacing pragma is a program unit pragma when applied to a program unit (see 10.1.5). 10.1.5(3-4): A program unit pragma shall appear in one of these places: At the place of a compilation_unit, in which case the pragma shall im- mediately follow in the same compilation (except for other pragmas) a library_unit_declaration that is a subprogram_declaration... and the pragma shall have an argument that is a name denoting that declaration. 10.1.1(5): library_unit_declaration ::= subprogram_declaration ... 10.1.1(9): A library unit is a program unit that is declared by a library_item. 6.1(2): subprogram_declaration ::= subprogram_specification; 6.1(4): subprogram_specification ::= procedure defining_program_unit_name parameter_profile | function defining_designator parameter_and_result_profile So far, GNAT seems to be correct. Pragma Convention is an interfacing pragma, an interfacing pragma is a program unit pragma, a program unit pragma immediately follows a subprogram declaration, and a subprogram declaration is a subprogram specification. However, consider the legality rule for a subprogram body: 6.3(4): In contrast to other bodies, a subprogram_body need not be the completion of a previous declaration, in which case the body declares the subprogram... Thus, a subprogram body that completes no other declaration is itself both body and declaration. The pragma Convention in the example therefore ful- fills the entire chain of legality rules: The body of CallbackProc in the package body of Callbacks is the declaration of CallbackProc, by 6.3(4). The body of CallbackProc (that is also the declaration) is a declaration of a library unit, by 10.1.1(9). The correct position of a program unit pragma pertaining to CallbackProc is immediately following the declaration, thus immediately following the body of CallbackProc, by 10.1.5(3-4). An interfacing pragma pertaining to CallbackProc is a program unit pragma, by B.1(30). Pragma Convention is an interfacing pragma, by B.1(4). Therefore, pragma Convention is correctly positioned following the body of CallbackProc. Although B.1(43) allows an implementation to place restrictions on inter- facing pragmas, since other compilers support the use of pragma Convention as shown, the restriction in the case of GNAT appears to be gratuitous and does compromise portability of Ada 95 code. Any "language lawyers" interested in commenting on the above, please respond by posting to this newsgroup or by e-mail. Chris Green Email cgreen@atc.com Advanced Technology Center Phone (714) 583-9119 22982 Mill Creek Drive ext. 220 Laguna Hills, CA 92653 Fax (714) 583-9213