Hello, folks!
When GPC opens a file, it reads one item ahead:
Program Foo;
Var F: File of Char; Ch: Char;
begin Assign ( F, 'foo.pas' ); reset ( F ); (* This already reads the first character. *) Ch:= F^; (* <-- Wouldn't this be early enough here??? *) close ( F ); end.
Since this causes problems with untyped files (which are currently being implemented) and already has caused bugs in other situations (see the thread "[BUG] GPC - a char killer?" discussed on this list in April) I think it would be only good to change this behaviour and to make GPC actually read the item when the file variable is accessed (see "<--" in the comment in the example above).
Translated to Borland Pascal (well ... the example above almost *is* in BP syntax; it does definitly *not* comply to ISO Pascal;-) this would mean that the physical `read' will happen at the point where `read' appears in the source:
reset ( F ); (* This already reads the first character. *) read ( F, Ch ); (* <-- Wouldn't this be early enough here??? *)
(Right now, it happens *before* the `read', and during the call to `read' the *next* item is read physically.)
(* O dear - I hardly understand my own mail; I hope you do. ;*)
If anybody knows what the standard says about this, please tell me through this list.
Greetings,
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [971005] maintainer GNU Pascal [971001] - http://home.pages.de/~gnu-pascal/ [971005]
Since this causes problems with untyped files (which are currently ... accessed (see "<--" in the comment in the example above).
I know this response is a bit dated, but IMO, if the read-ahead causes problems, and since the program doesn't depend on the first read, I don't see anything wrong with dropping the read-ahead.
See ya! Orlando Llanes
"Hey, we all did the drug thing, we all did the money thing, and eventually you find out that none of that stuff fixes anything, and we have nowhere else to go except to evolve spiritually and intellectually" -- Meredith Brooks
"Look out fo' flyeeng feet" O__/ a010111t@bc.seflin.org /|____. O <__. /> / \ ____________|_________ http://ourworld.compuserve.com/homepages/Monkey414