Hi all.
I'm Takashi Yamanoue, in Japan. (http://www.tobata.isc.kyutech.ac.jp/~yamanoue) (http://www.tobata.isc.kyutech.ac.jp/~yamanoue/researches/complang.html)
The output of the following program seems strange. Is it the specification? or a bug?
I've searched the archives of this list, and I've found out a similar bug in the Borland Pascal Format, and I've also found out the article which said that it was fixed.
I've updated the gcc and gpc. However, the following phenomenon was not fixed.
Thank you in advance.
Takashi, yamanoue@isc.kyutech.ac.jp
-------------------------------------------------------
program exercise28(input, output); const smax = 8; smax2 = 9; n = 10; type str = packed array[1..smax] of char; str2 = packed array[1..smax2] of char; var i, j: integer; s: array[1..n] of str; tmp: str; s2: array[1..n] of str2; tmp2: str; begin { the following part uses the 8 chars packed array}
s[1]:='abababab'; s[2]:='babababa'; s[3]:='12121212'; s[4]:='21212121'; s[5]:='cdcdcdcd'; s[6]:='dcdcdcdc'; s[7]:='56565656'; s[8]:='65656565'; s[9]:='bcbcbcbc'; s[10]:='cbcbcbcb';
for i := 1 to n - 1 do for j := n - 1 downto i do if s[j] > s[j + 1] then begin tmp := s[j]; s[j] := s[j + 1]; s[j + 1] := tmp end; for i := 1 to n do writeln('s[', i:2, '] = ', s[i]);
{ the following part uses the 9 chars packed array}
s2[1]:='abababab'; s2[2]:='babababa'; s2[3]:='12121212'; s2[4]:='21212121'; s2[5]:='cdcdcdcd'; s2[6]:='dcdcdcdc'; s2[7]:='56565656'; s2[8]:='65656565'; s2[9]:='bcbcbcbc'; s2[10]:='cbcbcbcb';
for i := 1 to n - 1 do for j := n - 1 downto i do if s2[j] > s2[j + 1] then begin tmp := s2[j]; s2[j] := s2[j + 1]; s2[j + 1] := tmp end; for i := 1 to n do writeln('s2[', i:2, '] = ', s2[i]) end. { the following is the output of this program.
yamanoue% gpc gpcbug.pas yamanoue% a.out s[ 1] = 21212121 s[ 2] = 12121212 s[ 3] = 65656565 s[ 4] = 56565656 s[ 5] = babababa s[ 6] = abababab s[ 7] = cbcbcbcb s[ 8] = bcbcbcbc s[ 9] = dcdcdcdc s[10] = cdcdcdcd s2[ 1] = 12121212 s2[ 2] = 21212121 s2[ 3] = 56565656 s2[ 4] = 65656565 s2[ 5] = abababab s2[ 6] = babababa s2[ 7] = bcbcbcbc s2[ 8] = cbcbcbcb s2[ 9] = cdcdcdcd s2[10] = dcdcdcdc yamanoue% gpc -v Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs gpc version 20000808, based on 2.95.2 19991024 (release) yamanoue%
The desired output is s[ 1] = 12121212 s[ 2] = 21212121 s[ 3] = 56565656 s[ 4] = 65656565 s[ 5] = abababab s[ 6] = babababa s[ 7] = bcbcbcbc s[ 8] = cbcbcbcb s[ 9] = cdcdcdcd s[10] = dcdcdcdc s2[ 1] = 12121212 s2[ 2] = 21212121 s2[ 3] = 56565656 s2[ 4] = 65656565 s2[ 5] = abababab s2[ 6] = babababa s2[ 7] = bcbcbcbc s2[ 8] = cbcbcbcb s2[ 9] = cdcdcdcd s2[10] = dcdcdcdc
}