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
}
On Tue, 15 Aug 2000, takashi yamanoue wrote:
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
If you change the type to type str = string ( smax ); str2 = string ( smax2 ); the output is correct
note: string ( ) is extended pascal string schema
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
}
hope this helps Russ
takashi yamanoue wrote:
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.
This seems to be a new bug, thanks for the report (takashi1.pas).
For some strange reason, GPC does the wrong comparisons (words in the first case, and bytes in the second one, while in both cases it should simply do string comparisons).
Frank
takashi yamanoue wrote:
Some teachers in our institute using the standard pascal in their classes, and they would like to use the standard pascal without extensions.
When you compile with `gpc --standard-pascal foo.pas', GPC will warn about extensions used in the program.
Peter
When you compile with `gpc --standard-pascal foo.pas', GPC will warn about extensions used in the program.
Thank you Peter. I compiled the bug program with this option. It seems that the bug program is a standard pascal.
Takashi