[fpc-devel] Val() with unsigned variable
bartjunk64 at gmail.com
Sat Jan 8 15:25:51 CET 2022
There's been a hot debate in the bugtracker about fixing Val() for
There's a patch (in fact there are several), and an attempt to speed
Val() up significantly by having helper functions for each type of
It looks like this is going to be fixed soon (and hopefully be merged
to 3.2 fixes).
This howver, is about
doesn't properly range check.
This applies to Val() with unsigned variables.
First of all: the fpc team needs to decide wether the currentbehaviour
where Val(string, unsigned_var, errorcode) causes range check errors
is acceptable, since the exact behaviour when input is "too large" may
be judged to be "undocumented", in which case any behaviour is OK.
E.g.: Should Val('256', ByteSizedVar, Code) cause a range check error,
or should it set Code to 3 and nothing more?
If causing rangecheck errors as OK in this case, then at least we can
say that the behaviour is incosistent with Val(string,
If causing rangecheck errors is not what we want, then we should
really try to fix this.
It may not come as a surprise that I'm advocating to fix Val so that
it does not cause range check errors.
If that is indeed what we want, I'm faced with a problem.
The val-helpers for unsigned variables do not have a DestSize
parameter like the val-helpers for signed variables have.
Without this info, I can see no possibility to fix this in the current
I know that Val() is a compiler proc.
For signed integers it calls fpc_Val_SInt_ShortStr or similar helper
(depends on bitness of cpu type a.o.).
For unsigned variables it calls fpc_Val_UInt_Shortstr or similar helper.
If the unsigned helper functions that handle multiple types (byte,
word, dword) need to have an extra parameter, I have no idea where in
the compiler the "magic" is to that decied which val-helper needs to
be called (and what paramters to pass).
And therefor I have no idea how to make it pass a DestSize parameter
if e.g. fpc_Val_UInt_Shortstr should be adapted to have such a
So, it boils down to 2 questions:
1: do we want to fix Val() for unsigned variables (like we did for
2: what changes are needed to extend fpc_Val_UInt_Shortstr et. all. to
receive a DestSize parameter from the "Val magic"?
If the answer to Q1 is "Yes" and somebody can explain how to do Q2 (or
preferrably implement that part), I can work in avoiding the range
check errors (that should be rather easy then).
(Mind you, I can only fix and test for/on i386 and X86_86, so I won't
touch specific code for CPU < 32-bit)
More information about the fpc-devel