Sign in Join

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

Mailing lists / fpc-pascal / 2020-02

$modeswitch from command line

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Sven Barth
to Mr Bee
Mr Bee wrote
Hi all, Is there a way to enable a mode switches from fpc command line?

Yes, using -M<x>, however these are discarded as soon as a $Mode directive is read (just like any $Mode directive resets any $Modeswitch directive).

Regards,
Sven

Reply by email

Mr Bee
to Sven Barth

As mention in the email title, what I meant is {$modeswitch} not {$mode} as explain here: https://www.freepascal.org/docs-html/prog/progsu105.html

For example, if I want to use extended record in objfpc mode, then I have to define {$mode objfpc}{$modeswitch advancedrecords}
in every single file that using the feature. I prefer to put it in a config file or call it from command line, as default setting, so my code is cleaner from such things.

Is it possible?
Thank you.
Regards,

–Mr Bee

Pada Selasa, 4 Februari 2020 13.42.10 WIB, Sven Barth via fpc-pascal menulis:

Mr Bee wrote
Hi all, Is there a way to enable a mode switches from fpc command line?

Yes, using -M<x>, however these are discarded as soon as a $Mode directive is read (just like any $Mode directive resets any $Modeswitch directive).

Regards,
Sven

Reply by email

zh loza
to Mr Bee

I personally find it very convenient to have a global include file for such features.
E.g. we have a global.inc with {$mode objfpc}{$modeswitch advancedrecords} and include it {$include global.inc} in every file of our project. This way we can easily modify a lot of compiler directives / macros that would affect all the units.

On Tue, Feb 4, 2020 at 10:41 AM Mr Bee via fpc-pascal <

Show quoted text 52 lines
wrote: As mention in the email title, what I meant is {$modeswitch} not {$mode} as explain here: https://www.freepascal.org/docs-html/prog/progsu105.html For example, if I want to use extended record in objfpc mode, then I have to define {$mode objfpc}{$modeswitch advancedrecords} in every single file that using the feature. I prefer to put it in a config file or call it from command line, as default setting, so my code is cleaner from such things. Is it possible? Thank you. Regards, –Mr Bee Pada Selasa, 4 Februari 2020 13.42.10 WIB, Sven Barth via fpc-pascal < > menulis: Am 03.02.2020 um 23:19 schrieb Mr Bee via fpc-pascal: > Hi all, > > Is there a way to enable a mode switches from fpc command line? > Yes, using -M<x>, however these are discarded as soon as a $Mode directive is read (just like any $Mode directive resets any $Modeswitch directive). Regards, Sven _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Mattias Gaertner
to Mr Bee: As mention in the email title, what I meant is {$modeswitch} not {$mode} as explain…
Show quoted text 9 lines
As mention in the email title, what I meant is {$modeswitch} not {$mode} as explain here: https://www.freepascal.org/docs-html/prog/progsu105.html For example, if I want to use extended record in objfpc mode, then I have to define {$mode objfpc}{$modeswitch advancedrecords} in every single file that using the feature. I prefer to put it in a config file or call it from command line, as default setting, so my code is cleaner from such things.

As Sven explained a $mode resets all modeswitches. What you need is a switch to alter modeswitch of a mode. And there is currently no such switch.

For example a syntax could be:
-MObjFPC+AdvancedRecords+AnsiStrings-NestedComments

Mattias

Reply by email

Jonas Maebe
to Mattias Gaertner
Mattias Gaertner wrote 6 lines
As Sven explained a $mode resets all modeswitches. What you need is a switch to alter modeswitch of a mode. And there is currently no such switch. For example a syntax could be: -MObjFPC+AdvancedRecords+AnsiStrings-NestedComments
$ cat tt.pp
program x;

{{test }

type
  tr = record
    procedure test;
  end;
  procedure tr.test;
    begin
    end;
begin
  writeln(sizeof(string));
end.

$ fpc -MObjFPC -Madvancedrecords -Mansistrings -Mnestedcomments- tt Free Pascal Compiler version 3.0.4 [2018/09/30] for x86_64 Copyright (c) 1993-2017 by Florian Klaempfl and others Target OS: Darwin for x86_64
Compiling tt.pp
Assembling (pipe) tt.s
Linking tt
16 lines compiled, 0.1 sec

$ ./tt
8

Setting a different mode resets all modeswitches to the default for that mode (since that's one of the main points of a mode). Setting a different modeswitch does not reset anything.

Jonas

Reply by email

Mr Bee
to Jonas Maebe

It’s a great info, Jonas. Thank you.
I didn’t know FPC has -M option for $modeswitch. Based on the official document¹, the -M option is to select language modes, not language features. I know changing language mode would reset mode switches. It’s no problem for me because I wrote the code and I stick to ObjFPC mode for all the code, no exception. But I want to use advanced record feature as well. By setting the language mode and language features in the global config, I don’t need to write them in every single file.

–Mr Bee
_____¹ A Alphabetical listing of command line options

|
|
| |
A Alphabetical listing of command line options

|

|

|

Pada Rabu, 5 Februari 2020 02.30.04 WIB, Jonas Maebe menulis:

Mattias Gaertner wrote 6 lines
As Sven explained a $mode resets all modeswitches. What you need is a switch to alter modeswitch of a mode. And there is currently no such switch. For example a syntax could be: -MObjFPC+AdvancedRecords+AnsiStrings-NestedComments
$ cat tt.pp
program x;

{{test }

type
  tr = record
    procedure test;
  end;
  procedure tr.test;
    begin
    end;
begin
  writeln(sizeof(string));
end.

$ fpc -MObjFPC -Madvancedrecords -Mansistrings -Mnestedcomments- tt Free Pascal Compiler version 3.0.4 [2018/09/30] for x86_64 Copyright (c) 1993-2017 by Florian Klaempfl and others Target OS: Darwin for x86_64
Compiling tt.pp
Assembling (pipe) tt.s
Linking tt
16 lines compiled, 0.1 sec

$ ./tt
8

Setting a different mode resets all modeswitches to the default for that mode (since that's one of the main points of a mode). Setting a different modeswitch does not reset anything.

Jonas

Reply by email

Jonas Maebe
to Jonas Maebe
Jonas Maebe wrote
> Based on the official > document¹, the -M option is to select language modes, not language features. It will be fixed.

Tomas already added it to the output of fpc -h in trunk in the mean time.

Jonas

Reply by email