[fpc-pascal] Stupid question: is this safe?
Bart
bartjunk64 at gmail.com
Fri Jan 29 12:39:40 CET 2010
Hi,
Is it safe to do the following?
var
W: Word;
U: UInt64;
{$R-} //range checkin off
begin
U := $0000000100000000;
W := U; // or W := Word(U);
end.
I know that the value that i assigned to W is "wrong" (and I can
handle that), but does it trash memory or cause other serious
problems?
Context: I have to deal with string input of arbitrary length (only
digits) that I have to convert to a Value of type Word.
For this I use Val().
Val('$0000000100000000', W, Err) gives W = 0; Err = 0 (indicating
there was no error);
I do not want to use rangechecking and then a try .. except (this
would slow down code dramatically).
So I thought I might use Val('$0000000100000000', U, Err) (U being of
type UInt64)
This has the advantage that any string which represents a value >
High(QWord) wil set Err to > 0.
After that I would have to assign the value in U to W (after a check
that the value in U is not "invalid" in the context of my code).
Bart
More information about the fpc-pascal
mailing list