comp.lang.ada
 help / color / mirror / Atom feed
From: cgreen@yosemite.atc.com (Christopher Green)
Subject: Placement of pragma Convention
Date: 1997/06/20
Date: 1997-06-20T00:00:00+00:00	[thread overview]
Message-ID: <5oervk$g07@newshub.atmnet.net> (raw)


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




             reply	other threads:[~1997-06-20  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-20  0:00 Christopher Green [this message]
1997-06-23  0:00 ` Placement of pragma Convention Tucker Taft
1997-06-23  0:00   ` Christopher Green
1997-06-24  0:00     ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox