Prof. A Olowofoyeku (The African Chief) wrote:
On 12 Aug 2003 at 21:54, Frank Heckenbach wrote:
[...]
"Val( S: String; var V; var Code: Integer)"
"... If the string is somehow invalid, the index of the offending character is stored in Code;
The question is if V is (guaranteed to be) zero then.
I wouldn't have thought so. The value of V might well be undefined. My understanding (which of course may be wrong) is that nothing is done with V unless the procedure call succeeds. So whatever was in V before the procedure call would still be there afterwards,
This would seem reasonable, but apparently not what BP does. This gives `0 3'.
program Foo; var x, y: Integer; begin x := 10; y := 20; Val ('34c', x, y); WriteLn (x, ' ', y) end.
but I do not think that even this is guaranteed.
It might still be undefined in BP. (My printed manual doesn't state it, either.) Then again, many things that are undocumented are relied upon by BP programmers and required for "full" compatibility. I don't know if this will be one of them.
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.)
Frank