[fpc-pascal] access violation?
Ryan Joseph
ryan at thealchemistguild.com
Fri Jul 27 19:41:51 CEST 2018
> On Jul 27, 2018, at 11:24 AM, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
>
> You can't if you compile with -CR.
> The RTL is not compiled with objectchecks, so it works there.
>
>> According to this test not only can you call methods on nil objects but
>> it calls the method statically (like a class method), i.e the test
>> prints “DoThis”. How is that possible?
>
> Self on x86_64 target is just a hidden argument.
> It won't work with virtual methods.
This is all news to me. I had no idea I was possibly compiling programs where I could call nil objects.
How do I disable this? I just ran this test program with -CR and I still calls the method statically.
Ryans-MacBook-Pro-2:~ ryanjoseph$ fpc -CR /Users/ryanjoseph/Desktop/macro_test/obj_test.pas
Free Pascal Compiler version 3.0.4 [2017/11/26] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Darwin for x86_64
Compiling /Users/ryanjoseph/Desktop/macro_test/obj_test.pas
Assembling (pipe) /Users/ryanjoseph/Desktop/macro_test/obj_test.s
Linking /Users/ryanjoseph/Desktop/macro_test/obj_test
19 lines compiled, 0.1 sec
Ryans-MacBook-Pro-2:~ ryanjoseph$ /Users/ryanjoseph/Desktop/macro_test/obj_test
DoThis
{$mode objfpc}
program obj_test;
type
TMyClass = class
procedure DoThis;
end;
procedure TMyClass.DoThis;
begin
writeln('DoThis');
end;
var
obj: TMyClass;
begin
obj := nil;
obj.DoThis;
end.
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list