[fpc-devel] Oddity: Longint being converted automatically to int64 and then assignment/conversion operator used/applied for/to structure variable...(i386) branch (2.4.2)
Skybuck Flying
skybuck2000 at hotmail.com
Thu Apr 7 08:01:24 CEST 2011
Hello,
I am currently inspecting the following compiler unit of 2.4.2
branch/release ninl.pas:
line 1371: enum:=tenumsym(tenumdef(def).firstenum);
line 1372: v:=tenumdef(def).maxval;
Problem is with line 1372.
.maxval is apperently an integer.
v however only knows int64 implicit conversions (operators)
v is defined as
line 1352: v : tconstexprint;
tconstexprint is defined as in constexp.pas:
type Tconstexprint=record
overflow:boolean;
case signed:boolean of
false:
(uvalue:qword);
true:
(svalue:int64);
end;
With conversion operators:
operator := (const u:qword):Tconstexprint;inline;
operator := (const s:int64):Tconstexprint;inline;
operator := (const c:Tconstexprint):qword;
operator := (const c:Tconstexprint):int64;
operator := (const c:Tconstexprint):bestreal;
(Notice the missing conversion operators for integer/longint)
Therefore at least in theory it does not know how to convert an integer to
an int64.
Further proof that this is indeed what's happening:
tenumdef is defined as follows in symdef.pas:
line 563: tenumdef = class(tstoreddef)
minval,
maxval : aint;
aint is defined as follows in globtype.pas:
line 51:
{ Natural integer register type and size for the target machine }
{$ifdef cpu64bitalu}
AWord = qword;
AInt = Int64;
Const
AIntBits = 64;
{$endif cpu64bitalu}
{$ifdef cpu32bitalu}
AWord = longword;
AInt = longint;
Const
AIntBits = 32;
{$endif cpu32bitalu}
{$ifdef cpu16bitalu}
AWord = Word;
AInt = Smallint;
Assumption is that conditional cpu32bitalu is active (for i386)
Therefore Aint = longint;
So to me it seems a bit of an oddity... at least it's an integer which is
being tried to assign to an int64... so at least no overflow...
However v is a structure and .maxvalue is an integer...
So how come a conversion is being done ? (there is no conversion operator
for this situation ?)
So I am guessing free pascal does some conversion from integer to int64 and
then assign int64 to v ?
Isn't that a bit weird ? I guess it's kinda beautifull as well.. it
automatically detects a conversion path... however this is not what Delphi
XE would do...
so a slight deviation... causing me headaches... but I'll have to deal with
it...
Unless ofcourse you guys actually think it's a bug... then it's up to you to
fix it... but for now I will add some conversion operators to try and get it
working/compiling...
Bye,
Skybuck.
More information about the fpc-devel
mailing list