[fpc-devel] Question about hint in bool eval / Mixing signed expressions and longwords gives a 64bit result
Jonas Maebe
jonas.maebe at elis.ugent.be
Tue Jan 8 09:58:02 CET 2013
On 08 Jan 2013, at 09:46, Martin wrote:
> I know it's a hint. And I know that implies it may mean noting, and
> yet is still present....
> Just trying to understand.
> if I did "int-longword" (same for addition and reverse order) then I
> need a int64 to hold the result.
>
> --- 1)
> Yet on my 32 bit Win vista (testing with 2.7.1 [2012/12/09] for
> i386 )
> fpc.exe -MObjFPC -Scghi -O1 -g -gl -vewnhi -l project1.lpr
>
> This gives no hint or warning (ignoring the "uninitialized" ones).
> It still gives none, even if I add " -Cro "
>
> program Project1;
> var
> a: LongWord;
> b: Integer;
> begin
> b := a - b; // (+$ffffffff) - ( -$7fffffff ) => can not be hold in
> "b" integer
> b := b - a;
> end.
>
> Given that this may actually truncate data (or give a run-error),
> IMHO a warning would be ok.
No hint is given because those operations are not evaluated using 64
bit arithmetic. They are no more dangerous than subtracting two
longwords or integers from each other, because the result of those
operations may not be representable either as a longword/integer.
> --- 2)
> But then, if I compare the 2 values, resulting in a boolean value
> (no risk of data truncation), then I get the hint
> project1.lpr(7,10) Hint: Mixing signed expressions and longwords
> gives a 64bit result
>
> program Project1;
> var
> a: LongWord;
> b: Integer;
> c: Boolean;
> begin
> c := a < b;
> end.
>
> In this case, I don't even see why a hint is needed? (I might
> overlook something).
The hint is because the compiler in this case converts the comparison
to a 64 bit operation (otherwise it's impossible to evaluate that
expression correctly), and 64 bit arithmetic is slower on 32 bit
platforms than 32 bit arithmetic. The hint is only about the potential
performance impact.
Jonas
More information about the fpc-devel
mailing list