Hello, Miguel!
Hello, everybody! (* Below are some words about ISO vs. Borland Pascal ... *)
According to João Miguel Domingos:
Thank you for your very useful help. I apolagize about my constant questions but I feel like someone in the desert searching for water.
No problem. One day, you will read another one's question on this list, know the answer, and "become water" yourself. :-)
This code was gaved by you and I think it is working properlly. After assigning the file I'm doing :
reset(f1); while not eof(f1) do begin seekread(f1,n); (n is integer); end;
After the seekread I want to read one record to the variable r1 of type tf1. What function do I use to do this.
`read'.
I know that GPC contains a get procedure but the only parametres that it accepts if the file variable.
You can use `get' as well, see below.
The following example program worked on my Linux box:
Program Test (output, f1);
type tf1 = record preco : integer; idade : integer; titulo : string[90]; end;
f1file = file[1..1000] of tf1;
var r1 : tf1; f1 : f1file; n : integer;
Procedure FAssign ( Var t: f1file; Name: String ); Var b : bindingtype; begin unbind(t); b:=binding(t); b.name:=name; bind(t,b); b:=binding(t); end;
begin FAssign (f1, 'test.dat'); rewrite(f1); for n:= 1 to 3 do begin r1.preco:= n; write (f1, r1); end (* for *); FAssign (f1, 'test.dat'); reset(f1); seekread(f1,2); get (f1); (* Read a value into the "file variable" `f1^' *) r1:= f1^; (* Assign the value of the file variable to `r1' *) writeln (r1.preco); (* Must be 2 *) end.
Or, using `read' (compatible to Borland Pascal which does not support `get'):
reset(f1); seekread(f1,2); read (f1, r1); (* Same as `get (f1); r1:= f1^'; *) writeln (r1.preco); (* Must be 2 *)
Without the `(output, f1)' in the program's headline it does not work. :-( I consider this a bug in GPC; others might consider this a feature.
Okay, ISO Pascal, as far as I have understood it, requires all files to appear in the program headline. While GPC partially supports this, I am sure that it does not yet comply to the requirements of the standard. OTOH, I consider this a bug anyway: I see no use for this, and - correct me if I am wrong - makes it a pain to write a large program (> 50000 lines) which reads and writes *many* files at *many* uncorrelated places.
Thus, GPC's standard behaviour should be as follows:
* Accept program headline parameters, but don't require them.
* If program headline parameters are given, do all checks required by ISO.
* If they are not given, allow to do everything with files which is allowed by UCSD and Borland Pascal.
* With `--standard-pascal', `--extended-pascal', or whatever, these parameters are required. (Already the case.)
I would be glad if somebody sent me test programs which show deficiencies in GPC's treatment of program headline parameters - both concerning ISO Pascal requirements and the treatment of files in UCSD/Borland Pascal.
For example, GPC should work with the following (but doesn't):
Program Test; (* Doesn't work without `F' parameter *)
Var F: file of Integer; n: Integer;
begin Assign ( F, 'test.dat' ); rewrite ( F ); for n:= 0 to 5 do write ( F, n ); close ( F ); reset ( F ); Seek ( F, 4 ); (* `Seek' unknown; must use `SeekRead' *) read ( F, n ); writeln ( n ); close ( f ); end.
There are probably more, independent cases where GPC fails to compile valid UCSD/Borland Pascal. And a similar example can certainly be constructed for valid Extended Pascal rejected by GPC - or invalid Extended Pascal accepted by "gpc --extended-pascal". Please help to improve GPC by finding all these cases and posting test programs here!
Greetings,
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201] maintainer GNU Pascal [970714] - http://home.pages.de/~gnu-pascal/ [970125]