comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@bix.com
Subject: Re: meaning of "current instance"
Date: 1999/11/12
Date: 1999-11-12T00:00:00+00:00	[thread overview]
Message-ID: <2hNW3.1742$dp.68215@typhoon-sf.snfc21.pbi.net> (raw)
In-Reply-To: 382b8a6f_4@news1.prserv.net

>I don't think your program will even compile.
Sorry, I tried to simplify more than was possible.
This prints "1 1", as seems nice, but unexpected, with one compiler,
but "5832148 1" with another compiler.  If X.J in function Init
is replaced by X.I, then the two compilers give
"39190036 1" and "0 1" respectively.  I presume either of X.I or X.J
in function Init is erroneous, right?  Is the Init function allowed
only to reference previously initialized values (ie, X.I could be
referenced by Init in "J : Integer := Init(T'access);"), or can
it reference any values (seems impossible) or are there no references
at all to initial values of the current instance that are legal?

package junk1 is
  type T is private;
  procedure dump(X : in T);
  function Init(X : access T) return Integer;

private
  function Stepper return Integer;

  type T  is record
    I : Integer := Init(T'access);
    J : Integer := Stepper;
  end record;

end junk1;

with ada.text_io;
use  ada.text_io;
package body junk1 is

  Current : Integer := 0;

  function Stepper return Integer is
  begin
    Current := Current+1;
    return Current;
  end Stepper;

  function Init(X : access T) return Integer is
  begin
    return X.J;   -- or X.I
  end Init;

  procedure dump(X : in T) is
  begin
    put_line(Integer'image(X.I)
             & Integer'image(X.J));
  end dump;

end junk1;

with junk1;
procedure junk2 is
  x : junk1.T;
begin
  junk1.dump(x);
end junk2;




  reply	other threads:[~1999-11-12  0:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-11  0:00 meaning of "current instance" Matthew Heaney
1999-11-11  0:00 ` tmoran
1999-11-11  0:00   ` Matthew Heaney
1999-11-12  0:00     ` tmoran
1999-11-11  0:00       ` Matthew Heaney
1999-11-12  0:00         ` tmoran [this message]
1999-11-12  0:00           ` Matthew Heaney
1999-11-12  0:00             ` tmoran
1999-11-12  0:00               ` Matthew Heaney
1999-11-13  0:00             ` Robert A Duff
1999-11-13  0:00           ` Nick Roberts
1999-11-13  0:00             ` Robert A Duff
1999-11-14  0:00               ` tmoran
1999-11-13  0:00                 ` Matthew Heaney
1999-11-15  0:00                   ` John English
1999-11-15  0:00                     ` Matthew Heaney
1999-11-11  0:00 ` Robert A Duff
1999-11-11  0:00   ` Matthew Heaney
1999-11-11  0:00     ` Tucker Taft
1999-11-15  0:00   ` Tucker Taft
1999-11-15  0:00     ` tmoran
1999-11-15  0:00       ` Tucker Taft
replies disabled

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