comp.lang.ada
 help / color / mirror / Atom feed
* Initialize - behaviour??
@ 1996-11-27  0:00 Sergio Silva
  1996-11-28  0:00 ` Sergio Silva
  1996-11-28  0:00 ` Paul Chardon
  0 siblings, 2 replies; 3+ messages in thread
From: Sergio Silva @ 1996-11-27  0:00 UTC (permalink / raw)
  Cc: silva


Hello everyone,

I have a problem on understanding the correct behaviour of initialize. I
expected an object not to be accessible to other procedures until
initialization has finished but that does not happen in the example
below.


I have the following tagged type:

   type Watcher_Type is new Limited_Controlled with record
      FileOne : Log_File.File_Type;
      Scanned : Log_File.Positive_Count := 1;
   end record;


with the follwoing initialize procedure:

   procedure Get_Ready (Watcher_object : in out Watcher_Type_Logger) is
      File_Name : String := "Logged.log";  
      I : Integer :=10;
   begin
      Create(File => Watcher_object.FileOne,
	     Mode => Out_File,
	     Name => File_Name(1..I));
   exception when others => Put_Line("WATCHER initialize logger");
   end Get_Ready;


and a procedure that uses the file, which looks like:

   procedure Log (Watcher: in out Watcher_Type_Logger;
	          Data   : in Data_Type;) is
      Input_Record;
   begin
      Input_Data.Data := Data;
      Write( Watcher.FileOne,Input_Record);----
   exception 
      when others => Put_Line ("WATCHER log");
   end Log;



If a task calls procedure Log at the very begining of an execution, it
happens that the attempt to write to the file occurs before the file is
created, so an exception is raised. I have looked at the LRM Section 7.6
and nothing specifies that initialization must end before any access to
the object is allowed. Does any body know anything about what the
behaviour should be? And, if the behaviour I am getting is correct: What
may be the motivation to allow such a thing?


Thanks for your comments,

Sergio

P.S. I am compiling with Gnat 3.07
P.P.S. I have solved the problem, of course by explicitly calling a
procedure that performs the initialization...
-- 

-----------------------------------------------------------------------------
Sergio Silva-Barradas
Dip.to di Elettronica e Informazione            
Politecnico di Milano                           Ph:       +(39)(2) 2399
3638 
P.zza Leonardo da Vinci 32                      Fax:      +(39)(2) 2399
3411 
I20133 Milan, Italy                             e-mail:
silva@elet.polimi.it




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

* Re: Initialize - behaviour??
  1996-11-27  0:00 Initialize - behaviour?? Sergio Silva
  1996-11-28  0:00 ` Sergio Silva
@ 1996-11-28  0:00 ` Paul Chardon
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Chardon @ 1996-11-28  0:00 UTC (permalink / raw)
  To: Sergio Silva


Hello,

	When you use a limited controlled type, and if you want objects of this
type to be initialized automatically (respectively finalize) when they
become in scope, you must redefines the procedure Initialize
(respectively finalize), that is to say :

the follwoing initialize procedure:
 
    procedure Initialize (Watcher_object : in out Watcher_Type_Logger)is
       File_Name : String := "Logged.log";
       I : Integer :=10;
    begin
       Create(File => Watcher_object.FileOne,
              Mode => Out_File,
              Name => File_Name(1..I));
    exception when others => Put_Line("WATCHER initialize logger");
    end Initialize;

and do the same for the procedure finalize. (See LRM 7.6 (2))

Is that your problem ? Hope so, Paul.




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

* Re: Initialize - behaviour??
  1996-11-27  0:00 Initialize - behaviour?? Sergio Silva
@ 1996-11-28  0:00 ` Sergio Silva
  1996-11-28  0:00 ` Paul Chardon
  1 sibling, 0 replies; 3+ messages in thread
From: Sergio Silva @ 1996-11-28  0:00 UTC (permalink / raw)
  Cc: silva


Errata corrige:


SORRY!, the procedure called "Get_Ready" in my previous message was
originally called "initialize". By mistake I posted the new version
where I initialize "manually". My doubt persists, so the example must be
read with "initialize" instead of "Get_Ready".

Thanks to Paul for pointing it out... 

Sergio




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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-27  0:00 Initialize - behaviour?? Sergio Silva
1996-11-28  0:00 ` Sergio Silva
1996-11-28  0:00 ` Paul Chardon

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