Recent

Author Topic: for in shortstring  (Read 1663 times)

bytebites

  • Hero Member
  • *****
  • Posts: 694
for in shortstring
« on: December 16, 2023, 01:41:18 pm »
Code: Pascal  [Select][+][-]
  1. program short;
  2. uses sysutils;
  3. var s:string[20];
  4.   x: Char;
  5. begin
  6.   s:=inttostr(12345);
  7.   for x in s do write(ord(x):4);
  8.   writeln;
  9. end.
  10.  

This code produces with 3.2
   49  50  51  52  53
but trunk version
   5  49  50  51  52  53   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0


Bart

  • Hero Member
  • *****
  • Posts: 5497
    • Bart en Mariska's Webstek
Re: for in shortstring
« Reply #1 on: December 16, 2023, 05:24:45 pm »
Confirmed.
I would say: report that as a bug.
(Unless Delphi behaves the same, which I cannot test, but even then....)

Bart

bytebites

  • Hero Member
  • *****
  • Posts: 694
Re: for in shortstring
« Reply #2 on: December 17, 2023, 04:13:20 pm »

Bart

  • Hero Member
  • *****
  • Posts: 5497
    • Bart en Mariska's Webstek
Re: for in shortstring
« Reply #3 on: December 17, 2023, 10:23:26 pm »
Not sure wether that gets noticed...
I dropped him a note in the original bugreport, hopefully he gets that.

Bart
« Last Edit: December 17, 2023, 10:29:04 pm by Bart »

wp

  • Hero Member
  • *****
  • Posts: 12527
Re: for in shortstring
« Reply #4 on: December 18, 2023, 12:32:06 am »
Delphi 11.3 CE, BTW, does it correctly:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2. var
  3.   s: String[10];
  4.   ch: AnsiChar;
  5. begin
  6.   s := 'abc';
  7.   for ch in s do
  8.     Write(ord(ch), ' ');
  9.   WriteLn;
  10.   ReadLn;
  11. end.

Output:
Code: [Select]
97 98 99

Bart

  • Hero Member
  • *****
  • Posts: 5497
    • Bart en Mariska's Webstek
Re: for in shortstring
« Reply #5 on: December 18, 2023, 08:24:57 am »
It's because "for .. in" for strings now uses Low and High instead of 1 and Length for it's boudaries.
It was introduced because "for .. in" for zero based strings (yes, we have a compiler directive for that) was off by one.
Obviousely it's a regression.

Bart

AlexTP

  • Hero Member
  • *****
  • Posts: 2521
    • UVviewsoft
Re: for in shortstring
« Reply #6 on: December 18, 2023, 08:39:54 am »

 

TinyPortal © 2005-2018