[comp.lang.ada] Sample Sequential_Io code

asp@SEI.CMU.EDU (Spencer Peterson) (02/16/88)

Here is some sample code that DOES compile correctly on the current version
of VAX Ada.

with Sequential_Io;
procedure Seq_Test is
    package Sio is new Sequential_Io(Integer);
    use Sio;
    f : File_Type;
    i : integer;
begin
    open( f, in_file , "test.sio");
    read( f, i );
    close( f );
end;

The problem you and the professor had was probably in placing the
instantiation of Sequential_Io correctly into one (or more compilation
units).  The code segment below is equally compilable:

with Sequential_Io;
package Sio is new Sequential_Io(integer);
-- The above makes Sio a valid library generic instantiation, nameable in any
-- subsequent compilation unit.

with Sio; use Sio; -- the 'use' is LEGAL here, as Sio is no longer a generic.
procedure Seq_Test is
use Sio; -- If you DON'T use it in the context clause, it's legal here also.
...      -- Code is the same, except that the instaniation is not needed.
end;

By the way, if the prof.'s PC compiler accepted "use Sequential_Io;", then it
has a bug(very probably), since a generic package cannot be 'used' directly 
without a prior instantiation, and the library name "Sequential_Io" is 
predefined and should ALWAYS refer to the package specified in the ARM, and 
hence should NOT a library unit nameable in a 'use' clause.  Technically, it
is NOT illegal to use the predefined library unit names(with an exception that
I would explain here) but it would be considered BAD programming style. 

Spencer Peterson
Member of the Technical Staff
Software Engineering Institute
Carnegie Mellon University
5000 Forbes Ave.
Pittsburgh, PA  15213
412-268-7608