[fpc-devel] StrToInt -- Strange behaviour
Sven Barth
pascaldragon at googlemail.com
Thu Feb 21 21:21:09 CET 2013
On 21.02.2013 21:01, Ewald wrote:
> Hello,
>
> Try running the following program and be amazed of the output:
>
> Program Test;
>
> Uses Sysutils;
>
> Begin
> WriteLn(StrToInt('x1'));
> WriteLn(StrToInt('x0'));
> WriteLn(StrToInt('xabcdef'));
> End.
>
>
> Apparently the StrToInt function interprets strings starting with an `x`
> as hexadecimal numbers? This behaviour seems rather strange to me
> (strings starting with 0x would be a bit more understandable, but then
> again, we're programming pascal here, not C) and it is not mentioned in
> the documentation. What do I do with it?
IntToStr simply calls through to Val and there is documented (more or
less) that it supports binary (%), octal (&) and hexadecimal ($, 0x)
values as well (see here:
http://www.freepascal.org/docs-html/rtl/system/val.html ). That it also
supports 'x' and 'X' as a prefix for hexadecimal values is because of
Delphi compatibility.
As a sidenote: the prefixes %, & and $ can be used in normal source code
as well.
> A- File a bug concerning incomplete documentation?
> B- File a bug concerning incorrect behaviour of StrToInt()?
> C- Do nothing and live with it.
> D- ....?
I'd say A. On the one hand a reference from StrToInt(64),
StrToInt(64)Def and TryStrToInt(64) to Val should be added and on the
other hand Val's documentation should be extended by the fact that '0x',
'X' and 'x' are valid prefixes for hexadecimal values as well.
And while we're at it references from the 32bit StrToInt variants to the
64bit variants could be added as well (they do exist the other way round
as one can see here:
http://www.freepascal.org/docs-html/rtl/sysutils/strtoint64.html ).
So if you would please be so kind to open a bug report :)
Regards,
Sven
More information about the fpc-devel
mailing list