comp.lang.ada
 help / color / mirror / Atom feed
* Is this legal Ada95?
@ 1997-11-06  0:00 Kevin Radke
  1997-11-06  0:00 ` Tucker Taft
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin Radke @ 1997-11-06  0:00 UTC (permalink / raw)



I was compiling some Ada83 code originally written under VMS
and the Dec Ada compiler, and Gnat v3.10p on NT gives me
the following error:

  foo.adb:11:56: object "Initial_Value" cannot be used before end
  of its declaration

This code has compiled successfully on 3 Ada83 compilers and
1 Ada95 compiler without problems.  (This doesn't mean it is
correct, just no one else has complained about it.)  I was
wondering if it is invalid somehow in Ada95 and the other
Ada95 compiler missed it, or if GNAT is being finicky.

Thanks!
Kevin

Here are the 3 files:
-- begin double_buffer.ads --
package Double_Buffer is

  generic
    type Item_Type is private;
    Initial_Value : in Item_Type;
  package Interface is
    procedure Put(Item : in     Item_Type);
    procedure Get(Item :    out Item_Type);
  end Interface;
end Double_Buffer;
-- end double_buffer.ads --

-- begin foo.ads --
generic
  type Item_Type is private;
  Initial_Value : in Item_Type;
package Foo is
  type Time_Tag_Type is new Integer;
  Null_Time_Tag : constant Time_Tag_Type := 0;

  procedure Bar (Item : in Item_Type);
end Foo;
-- end foo.ads --

-- begin foo.adb --
with Double_Buffer;

package body Foo is
  type Tagged_Item_Type is record
    Item     : Item_Type;
    Time_Tag : Time_Tag_Type;
  end record;

  package My_Buffer is new
    Double_Buffer.Interface (Tagged_Item_Type,
                             Initial_Value => (Item => Initial_Value,
                                               Time_Tag => Null_Time_Tag));
  procedure Bar (Item : in Item_Type) is
  begin
    null;
  end Bar;

end Foo;
-- end foo.adb --




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

* Re: Is this legal Ada95?
  1997-11-06  0:00 Is this legal Ada95? Kevin Radke
@ 1997-11-06  0:00 ` Tucker Taft
  0 siblings, 0 replies; 2+ messages in thread
From: Tucker Taft @ 1997-11-06  0:00 UTC (permalink / raw)



Kevin Radke (radke@cpre1.ee.iastate.edu) wrote:

: I was compiling some Ada83 code originally written under VMS
: and the Dec Ada compiler, and Gnat v3.10p on NT gives me
: the following error:

:   foo.adb:11:56: object "Initial_Value" cannot be used before end
:   of its declaration

: This code has compiled successfully on 3 Ada83 compilers and
: 1 Ada95 compiler without problems.  (This doesn't mean it is
: correct, just no one else has complained about it.)  I was
: wondering if it is invalid somehow in Ada95 and the other
: Ada95 compiler missed it, or if GNAT is being finicky.

Looks OK to me (and our Ada 95 front end).  GNAT 3.10p seems to 
be in the wrong here; it conceivably is being confused by
your use of "Initial_Value" twice.  

You might try changing the name of the formal parameter in one of 
your generics to be something other than Initial_Value, and make the 
corresponding change in your instantiation of Double_Buffer.Interface.
If this fixes the problem, then GNAT is apparently getting 
confused by the name reuse (though your use of the same
names for both is in fact perfectly legal).

: Thanks!
: Kevin

-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA

: Here are the 3 files:
: -- begin double_buffer.ads --
: package Double_Buffer is

:   generic
:     type Item_Type is private;
:     Initial_Value : in Item_Type;
:   package Interface is
:     procedure Put(Item : in     Item_Type);
:     procedure Get(Item :    out Item_Type);
:   end Interface;
: end Double_Buffer;
: -- end double_buffer.ads --

: -- begin foo.ads --
: generic
:   type Item_Type is private;
:   Initial_Value : in Item_Type;
: package Foo is
:   type Time_Tag_Type is new Integer;
:   Null_Time_Tag : constant Time_Tag_Type := 0;

:   procedure Bar (Item : in Item_Type);
: end Foo;
: -- end foo.ads --

: -- begin foo.adb --
: with Double_Buffer;

: package body Foo is
:   type Tagged_Item_Type is record
:     Item     : Item_Type;
:     Time_Tag : Time_Tag_Type;
:   end record;

:   package My_Buffer is new
:     Double_Buffer.Interface (Tagged_Item_Type,
:                              Initial_Value => (Item => Initial_Value,
:                                                Time_Tag => Null_Time_Tag));
:   procedure Bar (Item : in Item_Type) is
:   begin
:     null;
:   end Bar;

: end Foo;
: -- end foo.adb --




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

end of thread, other threads:[~1997-11-06  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-06  0:00 Is this legal Ada95? Kevin Radke
1997-11-06  0:00 ` Tucker Taft

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