Re: [fpc-pascal] Error: Can't take the address of constant expressions
On 26 Sep 2012, at 07:58, Vincent Snijders wrote: > 2012/9/25 Bernd : >> 2012/9/25 patspiper : >>> procedure test; >>> begin >>> Move(MyClass1.Ref.Data^, MyClass2.Ref.Data^, 1); >>> end; >> >> and if you cast it to some other pointer type before dereferencing the >> error goes away: >> >> procedure test; >> begin >> Move(MyClass1.Ref.Data^, PByte(MyClass2.Ref.Data)^, 1); >> end; >> >> But this should not be necessary. > > Why not? The error is correct. By using the type cast you tell the > compiler you know what you are doing and that is should not bother > doing the sanity check. If that were true, then using a local variable that is an untyped pointer would also have to fail. It is in fact a compiler bug. Jonas___ fpc-pascal maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Error: Can't take the address of constant expressions
On 26/09/12 08:58, Vincent Snijders wrote: 2012/9/25 Bernd: 2012/9/25 patspiper: procedure test; begin Move(MyClass1.Ref.Data^, MyClass2.Ref.Data^, 1); end; and if you cast it to some other pointer type before dereferencing the error goes away: procedure test; begin Move(MyClass1.Ref.Data^, PByte(MyClass2.Ref.Data)^, 1); end; But this should not be necessary. Why not? The error is correct. By using the type cast you tell the compiler you know what you are doing and that is should not bother doing the sanity check. So IMO, not a bug. Can anybody test under Delphi? The complete unit is in the OP. Stephano ___ fpc-pascal maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Error: Can't take the address of constant expressions
2012/9/25 Bernd : > 2012/9/25 patspiper : >> procedure test; >> begin >> Move(MyClass1.Ref.Data^, MyClass2.Ref.Data^, 1); >> end; > > and if you cast it to some other pointer type before dereferencing the > error goes away: > > procedure test; > begin > Move(MyClass1.Ref.Data^, PByte(MyClass2.Ref.Data)^, 1); > end; > > But this should not be necessary. Why not? The error is correct. By using the type cast you tell the compiler you know what you are doing and that is should not bother doing the sanity check. So IMO, not a bug. Vincent ___ fpc-pascal maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Error: Can't take the address of constant expressions
On 25/09/12 20:43, Bernd wrote: 2012/9/25 patspiper : procedure test; begin Move(MyClass1.Ref.Data^, MyClass2.Ref.Data^, 1); end; and if you cast it to some other pointer type before dereferencing the error goes away: procedure test; begin Move(MyClass1.Ref.Data^, PByte(MyClass2.Ref.Data)^, 1); end; But this should not be necessary. Thanks for the feedback. Submitted as: http://bugs.freepascal.org/view.php?id=22979 Stephano ___ fpc-pascal maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Error: Can't take the address of constant expressions
2012/9/25 patspiper : > procedure test; > begin > Move(MyClass1.Ref.Data^, MyClass2.Ref.Data^, 1); > end; and if you cast it to some other pointer type before dereferencing the error goes away: procedure test; begin Move(MyClass1.Ref.Data^, PByte(MyClass2.Ref.Data)^, 1); end; But this should not be necessary. ___ fpc-pascal maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Error: Can't take the address of constant expressions
2012/9/25 patspiper : > Hi, > > Despite > http://wiki.freepascal.org/User_Changes_2.4.0#Treating_direct-mapped_properties_as_regular_fields, > shouldn't the following be legal? I tested under FPC 2.6.1 and 2.7.1. This shouldn't even matter here since IMHO it should work even if Ref were a function (and it works if Ref is a function), it should always work as long as the expression before the ^ is a pointer type. And interestingly this works also (as it should): type TMyClass = class private FRef: Pointer; public property Ref: Pointer read FRef write FRef; end; var MyClass1, MyClass2: TMyClass; procedure test; begin Move(MyClass1.Ref^, MyClass2.Ref^, 1); end; but Move(MyClass1.Ref, MyClass2.Ref, SizeOf(TMyClass.Ref)); will give an error (as it should), no matter how its internally represented because the code that is using this property should not be expected to make assumptions about internal compiler optimizations, it should always treat it like a property. But your example should work, IMHO you have found a bug. ___ fpc-pascal maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Error: Can't take the address of constant expressions
Hi,
Despite
http://wiki.freepascal.org/User_Changes_2.4.0#Treating_direct-mapped_properties_as_regular_fields,
shouldn't the following be legal? I tested under FPC 2.6.1 and 2.7.1.
TMyRecord = record
Data: pointer;
end;
TMyClass = class
private
FRef: TMyRecord;
public
property Ref: TMyRecord read FRef write FRef;
end;
var
MyClass1, MyClass2: TMyClass;
procedure test;
begin
Move(MyClass1.Ref.Data^, MyClass2.Ref.Data^, 1);
end;
The complete program is attached.
Thanks,
Stephano
program constaddresstest;
{$IFDEF FPC}
{$mode delphi}
{$ENDIF}
{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
type
TMyRecord = record
Data: pointer;
end;
TMyClass = class
private
FRef: TMyRecord;
public
property Ref: TMyRecord read FRef write FRef;
end;
var
MyClass1, MyClass2: TMyClass;
procedure test;
begin
Move(MyClass1.Ref.Data^, MyClass2.Ref.Data^, 1);
end;
begin
end.
___
fpc-pascal maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Error: Can't take the address of constant expressions
On 21 Feb 2011, at 16:59, Roland Turcan wrote: > type TMyObj = class > private >MyPWord:PWord; >... > end; > > procedure TMyObj.Some; > begin > ... > Inc (Cardinal (MyPWord), 2); > ... > end; > > and compiler says %subj% > > This code works fine on 32bit compiler, but what should I change to get > this running on 64bit and get the code still compatible with 32bit > compiler as well. Change Inc (Cardinal (MyPWord), 2); into Inc (MyPWord); (note: *without* the "2"; that is implicit because MyPWord points to data items of size 2) Jonas___ fpc-pascal maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Error: Can't take the address of constant expressions
Hello all, I have this code: type TMyObj = class private MyPWord:PWord; ... end; procedure TMyObj.Some; begin ... Inc (Cardinal (MyPWord), 2); ... end; and compiler says %subj% This code works fine on 32bit compiler, but what should I change to get this running on 64bit and get the code still compatible with 32bit compiler as well. Thanks. -- Best regards, TRoland http://www.rotursoft.sk http://exekutor.rotursoft.sk ___ fpc-pascal maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
