Hello,
I have a (relatively large) program that needs to restrict itself to units available in classic Turbo Pascal (i.e. no SysUtils, no exceptions). I built a small function for getting the size of a file, or -1 if the file does not exist (see below) based on $I- and IOResult, just like we did several decades ago. The function works fine in isolation (the demo program below), but in the larger program I get an exception when `Reset` is called and the file does not exist.
An unhandled exception occurred at $00000001009C05D8:
EAccessViolation: Access violation
$00000001009C05D8
$00000001009D6498
I find it weird that I get an exception at all, because SysUtils is not used. I also don't understand why it fails in the larger program, but not in small demo case. The program header is the same, i.e. {$mode delphi} and the units are exactly what I use in both cases.
program FS;
uses
Keyboard, Dos, Math, Process;
function FSize(Name: String): Integer;
var
F: File;
begin
{$i-}
Assign(F, Name);
Reset(F);
if IOResult = 0 then
begin
FSize := FileSize(F);
Close(F);
end
else FSize := -1;
{$i+}
end;
begin
WriteLn('Size is ', FSize(ParamStr(1)), ' bytes.');
end.
Does anyone have an idea? I am on a Mac with M3 and Sequoia. FPC is 3.2.2.