Hi,
there's a strange case when using relative file names and changing the directory. (Incidentally I was made aware of this by a bugfix in the ncurses library (C code) some while ago ... ;-) Consider this program:
program Foo;
var i: Integer; f: Text;
begin Assign (f, 'test.dat'); Rewrite (f); WriteLn (f, 42); Close (f); ChDir ('..'); Reset (f); ReadLn (f, i); WriteLn (i) end.
It fails under both GPC and BP because `Reset' tries to open a file `test.dat' in a different directory than it was created.
Of course, this effect isn't limited to `Assign'. The issue applies to any way of storing file names, provided that changing directories is possible at all.
A solution would be to store the expanded file name (i.e., turn it into an absolute path whenever possible -- I currently don't know any case where it wouldn't be possible).
Of course, this wouldn't be strictly BP compatible, but I wonder if this is a "good" or "bad" incompatibility. (Of course, the difference would be subtler and more confusing if there actually was a file `test.dat' in the new directory.) Also, clearly a new `Assign' statement after the change of directory would refer to the new directory, as would be expected.
How do other compilers behave? What would be the expected behaviour of code like above if it actually occurs in practice?
Frank