Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2015-10

goto illegal in fpc?

8 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Schneider

Folks:

https://alum.mit.edu/www/toms/ftp/shell.p

This is a test program I use to check Pascal compilers. I could not figure out from the FPC site how "standard" it is. When I try to compile shell.p, I get:

% fpc shell.p
Free Pascal Compiler version 2.6.4 [2015/10/07] for x86_64 Copyright (c) 1993-2014 by Florian Klaempfl and others Target OS: Darwin for x86_64
Compiling shell.p
shell.p(211,1) Error: Goto statements aren't allowed between different procedures shell.p(234) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted
Error: /sw/bin/ppcx64 returned an error exitcode (normal if you did not specify a source file to be compiled)

The use of the goto is to escape the program when it detects an unresolvable error. I use ONLY ONE goto in a 'halt' proceedure and that gives a message and then does a goto to the end of the program.

As far as I know, jumping out of a procedure like this is standard Pascal. Many of my programs use this mechanism, so if it is not allowed, I will be forced to abandon FPC.

(Note: I never need goto for any other code so being forced to have gotos stay within a single proceedure seems to make goto totally useless.)

I thought that the -Sg flag would allow this but it didn't help.

Is there a (non standard!) exit function in fpc that I could use during compilation? (Then I could substitute it for the goto call before compiling.)

I used fink to install fpc. I'm on OS X 10.10.5. Since I just started, I'm not on the fpc list yet, so please include my email in responses.

Thanks,

Tom

Thomas D. Schneider, Ph.D.
Senior Investigator
National Institutes of Health
National Cancer Institute
Center for Cancer Research
Gene Regulation and Chromosome Biology Laboratory
Molecular Information Theory Group
Frederick, Maryland 21702-1201

https://schneider.ncifcrf.gov (current link)
https://alum.mit.edu/www/toms (permanent link)

Reply by email

Sven Barth
to Schneider: Folks: https://alum.mit.edu/www/toms/ftp/shell.p This is a test program I use to check…
"Schneider" wrote 15 lines
Folks: https://alum.mit.edu/www/toms/ftp/shell.p This is a test program I use to check Pascal compilers. I could not figure out from the FPC site how "standard" it is. When I try to compile shell.p, I get: % fpc shell.p Free Pascal Compiler version 2.6.4 [2015/10/07] for x86_64 Copyright (c) 1993-2014 by Florian Klaempfl and others Target OS: Darwin for x86_64 Compiling shell.p shell.p(211,1) Error: Goto statements aren't allowed between different

procedures

shell.p(234) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted Error: /sw/bin/ppcx64 returned an error exitcode (normal if you did not

specify a source file to be compiled)

Show quoted text 8 lines
The use of the goto is to escape the program when it detects an unresolvable error. I use ONLY ONE goto in a 'halt' proceedure and that gives a message and then does a goto to the end of the program. As far as I know, jumping out of a procedure like this is standard Pascal. Many of my programs use this mechanism, so if it is not allowed, I will be forced to abandon FPC.

By default Free Pascal only allows gotos inside the same function (and even there with a few restrictions) (the compiler follows Delphi and AFAIK also Turbo Pascal here). This is because goto is quite destructive regarding some newer language features that require cleanup. That said there is the modeswitch "nonlocalgoto" that you can enable (AFAIK that needs FPC 3.0.0 or newer).
Just add "{$modeswitch nonlocalgoto}" add the top of your program after any other mode directive (AFAIK there is also a possibility to set modeswitches on the command line).
AFAIK mode MacPas has that switch set by default (at least mode ISO does), so it might also help to add "{$mode macpas}" or add -Mmacpas as a parameter. This should also solve other compatibility problems.

Show quoted text 5 lines
(Note: I never need goto for any other code so being forced to have gotos stay within a single proceedure seems to make goto totally useless.) I thought that the -Sg flag would allow this but it didn't help.

-Sg only enables intrafunction gotos if they should be disabled (don't remember which mode disables them...)

Is there a (non standard!) exit function in fpc that I could use during compilation? (Then I could substitute it for the goto call before compiling.)

I'd suggest you to use Halt(ErrorCode) instead. It's defined in unit system.

Alternatively you could use the exception handling mechanisms that FPC "inherited" from Delphi.

Regards,
Sven

Reply by email

Sven Barth
to Schneider: Folks: https://alum.mit.edu/www/toms/ftp/shell.p This is a test program I use to check…
"Schneider" wrote

I've now looked at your example code a bit more. Using 3.0.0 (or in my case 3.1.1) it compiles if you pass -Miso as parameter. Getting it to run confuses me a bit however considering that I've never worked with ISO style input/output files. ;) Please note that support for such files is new (introduced with 3.0.0) and thus might be buggy. If you find any problems with them it would be nice if you report them. :)

As an addendum to my previous mail: one can set singular modeswitches using -Mxxx as well (e.g. -Mnonlocalgoto), these are however overridden if a mode directive in the code is encountered.

Regards,
Sven

Reply by email

Jonas Maebe
to Sven Barth

Sven Barth wrote on Fri, 09 Oct 2015:

Show quoted text 12 lines
Am 09.10.2015 12:34 schrieb "Schneider" : > > Folks: > > https://alum.mit.edu/www/toms/ftp/shell.p I've now looked at your example code a bit more. Using 3.0.0 (or in my case 3.1.1) it compiles if you pass -Miso as parameter. Getting it to run confuses me a bit however considering that I've never worked with ISO style input/output files. ;) Please note that support for such files is new (introduced with 3.0.0) and thus might be buggy. If you find any problems with them it would be nice if you report them. :)

The support for ISO-style input/output files was fixed in trunk after 3.0 was branched (in r30757), so I'm afraid it won't work yet in 3.0...

Jonas

Reply by email

Schneider
to Sven Barth: procedures specify a source file to be compiled) By default Free Pascal only allows gotos…

Sven:

-Sg only enables intrafunction gotos if they should be disabled (don't remember which mode disables them...)

Ok, so that's out.

Show quoted text 6 lines
> Is there a (non standard!) exit function in fpc that I could use > during compilation? (Then I could substitute it for the goto call > before compiling.) I'd suggest you to use Halt(ErrorCode) instead. It's defined in unit system.

That worked, thanks. Of course I had to rename my 'halt' proceedure something else. It would be possible to modify the program this way. But the next email nailed it ...

Tom

Thomas D. Schneider, Ph.D.
Senior Investigator
National Institutes of Health
National Cancer Institute
Center for Cancer Research
Gene Regulation and Chromosome Biology Laboratory
Molecular Information Theory Group
Frederick, Maryland 21702-1201

https://schneider.ncifcrf.gov (current link)
https://alum.mit.edu/www/toms (permanent link)

Reply by email

Schneider
to Sven Barth: I've now looked at your example code a bit more. Using 3.0.0 (or in my case 3.1.1) it…

Sven:

Show quoted text 9 lines
> https://alum.mit.edu/www/toms/ftp/shell.p I've now looked at your example code a bit more. Using 3.0.0 (or in my case 3.1.1) it compiles if you pass -Miso as parameter. Getting it to run confuses me a bit however considering that I've never worked with ISO style input/output files. ;) Please note that support for such files is new (introduced with 3.0.0) and thus might be buggy. If you find any problems with them it would be nice if you report them. :)

-Miso prevented the objection to the goto. So that's the simplest thing to do.

Thanks!

Now on to the next problem ...

Tom

Thomas D. Schneider, Ph.D.
Senior Investigator
National Institutes of Health
National Cancer Institute
Center for Cancer Research
Gene Regulation and Chromosome Biology Laboratory
Molecular Information Theory Group
Frederick, Maryland 21702-1201

https://schneider.ncifcrf.gov (current link)
https://alum.mit.edu/www/toms (permanent link)

Reply by email

Schneider
to Jonas Maebe: Sven Barth wrote on Fri, 09 Oct 2015: The support for ISO-style input/output files was…

Jonas:

The support for ISO-style input/output files was fixed in trunk after 3.0 was branched (in r30757), so I'm afraid it won't work yet in 3.0...

Perhaps this is related to my next issue.

egg 21% shell
shell 3.01
An unhandled exception occurred at $00000001000013CF : EInOutError : File not assigned
$00000001000013CF

I am able to add this code:

Assign (afile,'');
Assign (bfile,'');
Assign (shellp,'');

and then that does not occur.

However, when run from the command line the program gets stuck waiting for me.

Changing it to:

  Assign (afile,'afile');
  Assign (bfile,'bfile');
  Assign (shellp,'shellp');

then the program runs cleanly.

In GPC I was able to set it so that the file name assigned is the file string itself.

Is there a flag to set this?
I want to avoid using 'assign' in my code because it's not standard as far as I know.

(I could not find something useful at
http://www.freepascal.org/docs-html/user/userap1.html)

Tom

Thomas D. Schneider, Ph.D.
Senior Investigator
National Institutes of Health
National Cancer Institute
Center for Cancer Research
Gene Regulation and Chromosome Biology Laboratory
Molecular Information Theory Group
Frederick, Maryland 21702-1201

https://schneider.ncifcrf.gov (current link)
https://alum.mit.edu/www/toms (permanent link)

Reply by email