On Thu, 14 Aug 2003, Frank Heckenbach wrote:
Prof A Olowofoyeku (The African Chief) wrote:
Mirsad Todorovac wrote:
The other side of the story is that Val could be used more flexible, i.e. for parsing if "best effort" has been done, and string has been converted-up to the first invalid character/digit.
We could do that if we decide to interpret it as undefined.
However, since `Val' is a BP function, anyway, I'd tend to change GPC's behaviour and set the number to 0. (In the case where you want to ignore the trailing garbage, it's easy to pass the prefix to `Val' again.)
What Mirsad suggests seems to be what Delphi does (i.e., stop where the error starts, and return what was possible to convert before the error - but again the Delphi help file does not document this, so I am not sure that one should rely on this behaviour).
Perhaps we should leave it undefined until/unless someone provides a reference of clearly documented behaviour of other compilers. (If that's what we do, please mention it in the reference, Mirsad.)
I was thinking about how having the sane part of string converted and stored could provide extra functionality - that would add a means for the function to be used in i.e. numerical expressions parsing at little extra cost, since the number appears to be already converted (the right value appears in `x' in the case of only one invalid char).
Of course, provided that this is what we want. We could OTOH want either completely 'clean' string or nothing.
I can't tell the number of program's that do rely on BP or Delphi `Val' undocumented behavior.
Frank?
Mirsad