On 06/12/2012 12:06, Jonas Maebe wrote:
That's because cardinal-cardinal results in an int64, because of a.o.
http://bugs.freepascal.org/view.php?id=8321
So actually the message is just downgraded from Warning to Hint.
Yes, that's by design. The compiler has no special knowledge about the
ptrint or ptruint types. It is almost impossible to fix all hints for
non-trivial programs, and they only exist to help find possibly
suspicious locations in code (and typecasting an integer into a
pointer is such an expression). You can always disable a particular
hint with -vqXXX if you are not interested in it.
I have no issue with the hint. I understand Ptr(u)Int are no different
from all other int types. Just aliases.
I now see that I get the warning, if the type-to-be-casted is 64 bit and
I am on a 32bit system.
program Project1;
{$mode objfpc}{$H+}
var
p: Pointer;
a: int64; //qword;
begin
p := Pointer(a);
end.
project1.lpr(7,8) Warning: Conversion between ordinals and pointers is
not portable
Yet what I do not understand, is why I get that message as warning (as
opposed to a hint). If I understand it right (I have not tested, maybe
it gives a warning on 64 bit target too, if so ignore the rest), and I
compile for a 64bit target, then it downgrades to a hint again?
The only difference is, that in the above example, if compiled for a 32
bit system, I already may have broken code. But then what it actually
means is that I should get warning about a truncating the value.
b := byte(a);
Gives no warning at all.
It also truncates the warning. What is then special about potentially
truncating a value by using pointer(a)? If "pointer(a)" is worth a
warning (instead of a hint, why isn't byte(a)?
---
Not saying it needs to change. But trying to figure out the reason behind.
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel