Hi all,
Is there a way to enable a mode switches from fpc command line? Thank you.
Regards,
~Bee
Mailing lists / fpc-pascal / 2020-02
$modeswitch from command line
9 messages · 5 people · –
- JJonas Maebe 3
- MMr Bee 3
- MMattias Gaertner 1
- SSven Barth 1
- Zzh loza 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Mr Bee wroteHi 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
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 wroteHi 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
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
As mention in the email title, what I meant is {$modeswitch} not {$mode} as explain…
Show quoted text 9 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
Mattias
Mattias Gaertner wrote 6 lines
$ 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
8Setting 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
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
$ 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
8Setting 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
Mr Bee wroteIt’s a great info, Jonas. Thank you. I didn’t know FPC has -M option for $modeswitch.
Sven mentioned earlier that it does:
https://lists.freepascal.org/pipermail/fpc-pascal/2020-February/057337.html
Based on the official document¹, the -M option is to select language modes, not language features.
It will be fixed.
Jonas
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
