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,de68e4ddf10693,start X-Google-Attributes: gid103376,public From: dewar@gnat.com Subject: Multiple pragma Imports Date: 1998/12/26 Message-ID: <762u9n$kfn$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 425915781 X-Http-Proxy: 1.0 x11.dejanews.com:80 (Squid/1.1.22) for client 166.72.81.174 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Sat Dec 26 15:10:47 1998 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1998-12-26T00:00:00+00:00 List-Id: 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