Is this legal? (Language lawyer question)

ada

    Next

  • 1. Multiple copies of ( Download gnat for SPARC)
    I notice that three copies of my (same) message had been posted. I don't know why Netscape posted three copies of my message. Sorry for the troubles. Adrian Hoe wrote: > Hi, > > It's been a long time. I just acquire a Sun Blade 150 and have Solaris 9 > installed. Aprt from Sun C/C++ compiler, there is no gcc/gnat in the > system. Where can I download the gcc/gnat compiler for SPARC Solaris 9? > Has anyone packaged any such binary for download? > > Thank you. > > Adrian Hoe >
  • 2. Overlapping ranges
    "David C. Hoos" < XXXX@XXXXX.COM > wrote in message news:PGAJa.19179$ XXXX@XXXXX.COM ... > Neither example will compile because the declaration > subtype x1_and_x2_range is range x1(x2'first)..x1'last; > is illegal; Sorry, just a typing error on my part. The line should have read: subtype x1_and_x2_range is x1 range x1(x2'first)..x1'last; A cut and past from AdaGide follows (which compiles fine): package overlap is type x1 is range 0..255; type x2 is range 127.. 2**15-1; subtype x1_and_x2_range is x1 range x1(x2'first)..x1'last; function f(x: x1) return boolean; end; Sorry for the typo omission. Doesn't change the rest of it though.
  • 3. Boehm-Demers-Weiser conservative garbage collector and GNAT
    Florian Weimer < XXXX@XXXXX.COM > writes: > Stephen Leake < XXXX@XXXXX.COM > writes: > > > I wrote a container library that does all the memory management I > > need. > > How do you prevent client code from keeping references to objects in > the container at the point of its finalization? My library does allow this. It is not a bullet-proof, "assume the client is an idiot" library. See the discussion on Grace lists for some reasons why. however, I normally code my apps so the container is always active; it's created when the app starts, and is one of the last things finalized when the app is shutting down. > Is erroneous execution a possibility? Yes, in the sense that Ada + my library allows it. > I don't think memory leaks are the most severe problem, dangling > references are. Yes. However, note that I said "all the memory management I need", not "all the memory protection a novice needs". Some small amount of discipline is expected on the part of the client; the goal is to get a good balance between container efficiency and protection against bugs. Now someone will say "C struck a better balance"; more power to them :). The issue of whether garbage collection is a good thing for novice programmers is an interesting one. My initial take would still be "no - don't let them get used to the crutch". But I'm willing to be convinced. -- -- Stephe

Is this legal? (Language lawyer question)

Postby adam » Sun, 17 Aug 2003 12:36:44 GMT

I've run into some Ada code that is publicly available on the Internet
that doesn't look legal to me.  The rules involved are kind of
complex, so I'd like to make sure I haven't missed something.

The code declares a generic that starts out like this:

generic
   type Item (<>) is abstract tagged private;
   with function "=" (L, R : Item'Class) return Boolean is <>;
   type Item_Ptr is access all Item'Class;
   [etc.]
package Pkg is ...

In the body, there's a construct that looks like this:

package body Pkg is ...

   procedure Proc (Elem : Item'Class) is ...
   begin
      ...
      if ZZZ.all = Elem then ...   -- Ambiguous?

where the type of ZZZ is Item_Ptr.

I can't see how this wouldn't be ambiguous.  Although ZZZ.all and Elem
both have type Item'Class, it appears to me that there are two "="
functions visible at that point:

   function "=" (L, R : Item) return Boolean;
   function "=" (L, R : Item'Class) return Boolean;

where the first one is the predefined operator of the generic formal
type Item (see RM95 12.5(8)), and the second one is the generic formal
function declared above.  Applying 8.6(22-23), the expected type for
the parameters in the first function is Item, and that means that it's
acceptable for the actual parameter to resolve either to Item or
Item'Class.  The consequence is that both of the above functions are
acceptable interpretations for the construct, and thus the construct
should be ambiguous.

So what have I missed?

                                -- thanks, Adam

Re: Is this legal? (Language lawyer question)

Postby Robert I. Eachus » Fri, 22 Aug 2003 05:50:45 GMT





Please forward the actual example to  XXXX@XXXXX.COM .  I've 
looked at it, and I think that "we all know" what is meant, but that 
isn't what the standard says...

-- 
                                               Robert I. Eachus

"As far as I'm concerned, war always means failure." -- Jacques Chirac, 
President of France
"As far as France is concerned, you're right." -- Rush Limbaugh


Similar Threads:

1.Why constructing functions is a mess [was Language lawyer question: task activation (was: Language lawyer question: task activation))

2.Language lawyer question: Limited Views

On Dec 31 2008, 9:59 am, Maxim Reznik < XXXX@XXXXX.COM > wrote:
> Consider
> package Pkg is
>    type T;
>    type T is null record;
> end Pkg;
>
> According to 10.1.1(12.3/2)
> "The limited view of a package contains: ... For each type_declaration
> in the visible part, an incomplete view of the type..."
>
> limited view for it would be:
>
> package limited view Pkg is
>    type T;  --  for declaration type T;
>    type T;  --  for declaration type T is null record;
> end Pkg;
>
> Why two implicit declaration of T are allowed here?
> Is second "type T;" completion for first?

I suppose the answer is that the RM says that the implicit declaration
of the limited view contains an "incomplete view" of a type, not an
actual "type declaration", so the syntax rules having to do with
declarations don't actually apply since these are not really
declarations.  In any case, I wouldn't worry about it; the limited
view contains an incomplete view of T.  I'm someone who worries a lot
about the tiniest potential ambiguities in the RM, but even this one
doesn't concern me at all.

                                 -- Adam

3.Language lawyer question: Equality on 'Access attributes

Given this code:

package Pak1 is
    type Ptr1 is access all Integer;
    X : aliased Integer;
    Y : aliased Integer;
    B : Boolean := X'Access = Y'Access;
end Pak1;

GNAT gives me this error: "two access attributes cannot be compared
directly / they must be converted to an explicit type for comparison".

But I can't figure out why this should be an error.  Based on my
understanding of the language: The compiler needs to figure out
whether the interpretation of "X'Access = Y'Access" in which "="
denotes the equality operator implicitly defined for Ptr1 is an
acceptable interpretation (8.6(10-14)).  For a call to this "="
function, 6.4.1(3) says that the expected type for each argument is
Ptr1.  According to 3.10.2, X'Access and Y'Access do not have a
particular type out of context, but rather the types of these
constructs are determined by the expected type; when determining
whether these can be used as parameters to "=", the expected type is
Ptr1, and clearly it's legal to use X'Access or Y'Access in a
construct where the expected type is Ptr1.  So as far as I can tell,
this *is* an acceptable interpretation; and since there's only one "="
visible whose parameter types are access-to-integer, the requirement
of 8.6(30) is met that there be exactly one acceptable interpretation
of the function call, and thus this should be legal.  (If there were a
second access type, "type Ptr2 is access all integer", then B's
initialization expression would be ambiguous, since there would then
be two visible "=" operators for which the interpretation would be
acceptable.)  Note that the modified version of 3.10.2(2) in
AI95-00235 doesn't affect this analysis.

Is this analysis correct?  If not, where did I go wrong?  If I'm wrong
and GNAT is right, then could someone explain to me just how 8.6 and
3.10.2 are to be applied together when an 'Access attribute is used? 
The wording of the GNAT error message makes it appear to me that
GNAT's authors interpreted the RM as prohibiting this construct---but
I can't figure out where in the RM this would be prohibited.

                                     -- thanks, Adam

4.Why constructing functions is a mess [was Language lawyer question: task activation

Dmitry A. Kazakov wrote:

> Topic: large system design, information hiding:
> 
>       type T (<>) is abstract tagged limited private;
>    private
>       type T (...constraints...) is abstract tagged limited record
>          ...
>       end record;
> 
> In order to be used in
> 
>    type S is new T with ...;
>    function Create (....) return S;

How/Why should this derivation be possible? (Deriving publicly
from an abstract limited type with unknown discriminants--to me,
the <> signals the intent of the author of T, namely that T
should be considered none of our business?)


> Remember? Constructor is not function. It never will. See the problem?

Assuming C++ has constructors, will your arguments apply
in the following examples (just trying to understand):

class T
{
public:
  virtual void op() = 0;
private:
  T(char constraint) : c(constraint) {}
  char c;
};

class S : public T
{
public:
  S() {}
};

(Note: no suitable default constructor in T)

5.Language lawyer question: task activation

Should this program deadlock?  I don't think it should (and I think it
should display "E1 accepted"), based on my understanding about when
task activation is supposed to occur for the function result.  But
perhaps there's something about the relation between task activation
and masters that I don't understand.  Anyway, this hangs when I
compile it with GNAT and run it---is this correct or not?

                                        -- thanks, Adam

with Text_IO;
procedure Test is

    task type TType is
        entry E1;
    end TType;

    task body TType is
    begin
         accept E1 do
            Text_IO.Put_Line ("E1 accepted");
         end E1;
    end TType;

    function Func return TType is
    begin
        return X : TType;
    end Func;

    procedure Do_It (X : TType) is
    begin
        X.E1;
    end Do_It;

begin
    Do_It (Func);
end Test;

6. Why constructing functions is a mess [was Language lawyer question: task activation

7. Language lawyer question: access discriminants

8. language lawyer question, PURE subroutines again



Return to ada

 

Who is online

Users browsing this forum: No registered users and 18 guest