Greetings, Having installed gpc 20060325, based on gcc-3.4.4 in replacement of gpc 20041218, based on gcc-3.3.3 I discovered that some programs which worked on the earlier version don't work on the later one. I narrowed the problem down to changes in the behaviour of goto.
program gototest; label 9999; procedure try; begin goto 9999; end; { try } begin try; 9999: end.
The program gototest.p is compiled by both compilers. The following
program gototest1; label 9999; procedure try; begin goto 9999; end; { try } begin repeat try; 9999: until 0=0; end.
is compiled by gpc 20041218 but the newer compiler gives the following error:
gpc --classic-pascal gototest.p gototest.p: In main program: gototest.p:10: error: invalid target for nonlocal `goto'
I have had a look at the ISO7185 specification, and though I am not an expert in these matters, it seems to me that the newer compiler is behaving incorrectly.
Incidentally FreePascal gives the following error for both programs:
Free Pascal Compiler version 2.2.2 [2008/10/26] for x86_64 Copyright (c) 1993-2008 by Florian Klaempfl Target OS: Linux for x86-64 Compiling gototest.p gototest.p(5,13) Error: Goto statements aren't allowed between different procedures gototest.p(14) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted Error: /usr/bin/ppcx64 returned an error exitcode (normal if you did not specify a source file to be compiled)
Are any of the compilers behaving as specified in the ISO7815 standard?
Best wishes,
John O.
John Gordon Ollason wrote:
Greetings, Having installed gpc 20060325, based on gcc-3.4.4 in replacement of gpc 20041218, based on gcc-3.3.3 I discovered that some programs which worked on the earlier version don't work on the later one. I narrowed the problem down to changes in the behaviour of goto.
program gototest; label 9999; procedure try; begin goto 9999; end; { try } begin try; 9999: end.
The program gototest.p is compiled by both compilers. The following
program gototest1; label 9999; procedure try; begin goto 9999; end; { try } begin repeat try; 9999: until 0=0; end.
is compiled by gpc 20041218 but the newer compiler gives the following error:
gpc --classic-pascal gototest.p gototest.p: In main program: gototest.p:10: error: invalid target for nonlocal `goto'
I have had a look at the ISO7185 specification, and though I am not an expert in these matters, it seems to me that the newer compiler is behaving incorrectly.
ISO7185 says:
: The label shall be permitted to occur in a goto-statement G (see : 6.8.2.4) if and only if any of the following three conditions is : satisfied. : : a) S contains G. : : b) S is a statement of a statement-sequence containing G. : : c) S is a statement of the statement-sequence of the compound-statement of the : statementpart of a block containing G.
Though this is hardly readable, the "statementpart of a block" means that the target of a non-local goto must be in the outermost scope of the procedure. (To understand that, you have to follow the grammar rules.)
So, the old gpc was too permissive, the new one behaves acoording to ISO.
Incidentally FreePascal gives the following error for both programs:
Free Pascal Compiler version 2.2.2 [2008/10/26] for x86_64 Copyright (c) 1993-2008 by Florian Klaempfl Target OS: Linux for x86-64 Compiling gototest.p gototest.p(5,13) Error: Goto statements aren't allowed between different procedures
Well, Free Pascal doesn't allow non-local gotos at all (and doesn't claim to support ISO Pascal).
Frank
Frank,
My mistake was misunderstanding the defintion of a statement-sequence.
Thanks.
John O.
ISO7185 says:
: The label shall be permitted to occur in a goto-statement G (see : 6.8.2.4) if and only if any of the following three conditions is : satisfied. : : a) S contains G. : : b) S is a statement of a statement-sequence containing G. : : c) S is a statement of the statement-sequence of the compound-statement of the : statementpart of a block containing G.
Though this is hardly readable, the "statementpart of a block" means that the target of a non-local goto must be in the outermost scope of the procedure. (To understand that, you have to follow the grammar rules.)
So, the old gpc was too permissive, the new one behaves acoording to ISO.
Incidentally FreePascal gives the following error for both programs:
Free Pascal Compiler version 2.2.2 [2008/10/26] for x86_64 Copyright (c) 1993-2008 by Florian Klaempfl Target OS: Linux for x86-64 Compiling gototest.p gototest.p(5,13) Error: Goto statements aren't allowed between different procedures
Well, Free Pascal doesn't allow non-local gotos at all (and doesn't claim to support ISO Pascal).
Frank