comp.lang.ada
 help / color / mirror / Atom feed
* Multiple pragma Imports
@ 1998-12-26  0:00 dewar
  1998-12-27  0:00 ` Jerry van Dijk
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: dewar @ 1998-12-26  0:00 UTC (permalink / raw)


I thought I would give a heads up on a problem we
have found in GNAT that we suspect exists in other
compilers (certainly DEC Ada 83 for example). Consider
the following:

   function Junk return Integer;
   pragma Import (C, Junk, "junk");

   function Junk return My_Integer;
   pragma Import (C, Junk, "junk");

We have seen this pattern in several bindings, including
the x11 bindings from Intermetrics. But the above code is
in fact illegal.

The problem is that the second pragma Import applies to
*both* of the function declarations. This is a consequence
of the last sentence in B.1(22):

  If the local_name denotes more than one entity, then
  the pragma Import is the completion of all of them.

This means that we have two pragma Imports for the first
function declaration, but this violates the last sentence
of 3.11(7):

  At most one completion is allowed for a given
  declaration.

We have fixed GNAT to properly reject the above program,
but we suspect that the above construction is quite
common, and that other compilers besides GNAT have
accepted this in the past.

So this is a heads up, and an invitation for discussion.
(to me, I think it would be far better if the rule were
that pragma Import acts as a completion only to entities
which have not already been completed, but unfortunately
that is not the way the language is defined).

The proper coding for the case where the same pragma Import
is expected to apply to all entities is simply to give just
one such pragma Import, so all you need to do is to remove
the first pragma Import to make the above code legal, and
to make it do what you want.

In the case where there are different imports, as in:

   function Junk return Integer;
   pragma Import (C, Junk, "junk1");

   function Junk return My_Integer;
   pragma Import (C, Junk, "junk2");

This is still of course illegal, but GNAT was silently
ignoring the first pragma Import completely, which is
definitely not what is wanted. The proper way of achieving
the effect of the second example is to use renaming so that
the entity in the pragma Import is unique.

I would be delighted to find out that my analysis is
incorrect here, but I am pretty sure it is right, and I
have discussed it with other folk, including Bob Duff,
before posting here.

Robert Dewar
Ada Core Technologies




-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~1999-01-07  0:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-26  0:00 Multiple pragma Imports dewar
1998-12-27  0:00 ` Jerry van Dijk
1998-12-27  0:00   ` Larry Kilgallen
1998-12-27  0:00     ` Jerry van Dijk
1998-12-28  0:00       ` dewar
1998-12-28  0:00         ` Jerry van Dijk
1998-12-27  0:00     ` Tom Moran
1998-12-28  0:00       ` dewar
1998-12-28  0:00   ` dewar
1998-12-28  0:00 ` Tom Moran
1999-01-06  0:00 ` Matthew Heaney
1999-01-07  0:00   ` Robert I. Eachus
1999-01-07  0:00   ` dewar

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