Frank Heckenbach wrote:
Mirsad Todorovac wrote:
1. Does Borland Pascal do teh same, or is it a GPC bug?
Now I'm surprised. BP seems to always set x = 0 when ec <> 0, i.e. when invalid characters are found.
Can any BP user confirm whether that's the expected behaviour? (I've always used `Val' for entire number strings, so ec <> 0 would be an error in my programs, so I've never noticed this behaviour.)
If that's really so in BP, I suppose we should change it in GPC.
From the Turbo Pascal 6.0 Library Reference: "Val( S: String; var V; var Code: Integer)" "... If the string is somehow invalid, the index of the offending character is stored in Code; otherwise, Code is set to zero. Val performs range-checking differently depeding on the state of {$R} and the type of the parameter V. With range-checking on, {$R+}, an out-of-range value always generates a run-time error. With range-checking off, {$R-}, the values for an out-of-range value vary depending upon the data type of V. If V is a Real or Longint type, the value of V is undefined and Code returns a nonzero value. For any other numeric type, Code returns a value of zero, and V will contain the results of an overflow calculation (assuming the string value is within the long integer range)." "... Restrictions. Trailing spaces must be deleted." Regards, Adriaan van Os