Recent

Author Topic: "Note: passing compiler option -M twice with different values"  (Read 613 times)

creaothceann

  • Full Member
  • ***
  • Posts: 109
In Lazarus I'm setting the syntax mode (menu | Project | Project Options | Compiler Options | Parsing | Syntax mode) to Free Pascal ("-Mfpc").

In the "Custom Options" I set these: -CfAVX2 -CpCOREAVX2 -Madvancedrecords -Mdefaultparameters -Mout -Mresult

The result is that my project compiles successfully, but in the messages window I get the hint "Note: passing compiler option -M twice with different values". Do I just disable that hint (somehow)?

Thausand

  • Full Member
  • ***
  • Posts: 234
Re: "Note: passing compiler option -M twice with different values"
« Reply #1 on: April 07, 2019, 07:42:31 pm »
In the "Custom Options" I set these: -CfAVX2 -CpCOREAVX2 -Madvancedrecords -Mdefaultparameters -Mout -Mresult

The result is that my project compiles successfully, but in the messages window I get the hint "Note: passing compiler option -M twice with different values". Do I just disable that hint (somehow)?
Not must disable !!! you make error.

-M only for language mode. No for mode switch.

add:

option command line -M write help here https://www.freepascal.org/docs-html/user/userap1.html
Code: [Select]
-M<x>  Set language mode to <x> 
      -Mfpc      Free Pascal dialect (default) 
      -Mobjfpc   FPC mode with Object Pascal support 
      -Mdelphi   Delphi 7 compatibility mode 
      -Mtp       TP/BP 7.0 compatibility mode 
      -Mmacpas   Macintosh Pascal dialects compatibility mode 
      -Miso      ISO 7185 mode 
      -Mextendedpascal ISO 10206 mode 
      -Mdelphiunicode Delphi 2009 and later compatibility mode

$MODESWITCH write help here https://www.freepascal.org/docs-html/prog/progsu105.html#x113-1140001.3.22
Code: [Select]
{$MODESWITCH XXX} 
{$MODESWITCH XXX+} 
{$MODESWITCH XXX-}
can make in program source or unit
« Last Edit: April 07, 2019, 08:17:29 pm by Thausand »

creaothceann

  • Full Member
  • ***
  • Posts: 109
Re: "Note: passing compiler option -M twice with different values"
« Reply #2 on: April 07, 2019, 08:33:09 pm »
I thought I read somewhere that I can enable features like that, though I can't seem to find it again...

So, then how come I can compile my code when these options are passed to the compiler, but can't when I leave them out? I've added the project as an attachment.

Thausand

  • Full Member
  • ***
  • Posts: 234
Re: "Note: passing compiler option -M twice with different values"
« Reply #3 on: April 07, 2019, 09:06:36 pm »
I thought I read somewhere that I can enable features like that, though I can't seem to find it again...
Sorry, i try and not seem to find. If you see then please write.

Quote
So, then how come I can compile my code when these options are passed to the compiler, but can't when I leave them out? I've added the project as an attachment.
Because i wrong and you right  :)

Code: [Select]
[0.070] Handling option "-MOBJFPC"
[0.070] interpreting option "-MOBJFPC"
[0.070] Macro defined: FPC_OBJFPC
[0.070] Handling option "-MADVANCEDRECORDS"
[0.070] interpreting option "-MADVANCEDRECORDS"

Note important . other way:
Code: [Select]
[0.055] Handling option "-MADVANCEDRECORDS"
[0.055] interpreting option "-MADVANCEDRECORDS"
[0.055] Handling option "-MOBJFPC"
[0.055] interpreting option "-MOBJFPC"
[0.055] Macro defined: FPC_OBJFPC

2.359] Searching file Test_BTB_History.lpr... found
[2.359] (TEST_BTB_HISTORY) Load from TEST_BTB_HISTORY (implementation) unit U_TOOLS
[2.359] Test_BTB_History.lpr(19,1) (TEST_BTB_HISTORY) Parsing implementation of Test_BTB_History.lpr
[2.359] Test_BTB_History.lpr(23,3) Fatal: Syntax error, "identifier" expected but "TYPE" found
[2.477] Fatal: Compilation aborted
Order important.

I not know this possible. Thank you for learn me.

creaothceann

  • Full Member
  • ***
  • Posts: 109
Re: "Note: passing compiler option -M twice with different values"
« Reply #4 on: April 07, 2019, 09:20:18 pm »
I thought I read somewhere that I can enable features like that, though I can't seem to find it again...
Sorry, i try and not seem to find. If you see then please write.
-Mresult was mentioned on this page: http://wiki.freepascal.org/User_Changes_2.6.0

Code: [Select]
[0.070] Handling option "-MOBJFPC"
[0.070] interpreting option "-MOBJFPC"
[0.070] Macro defined: FPC_OBJFPC
[0.070] Handling option "-MADVANCEDRECORDS"
[0.070] interpreting option "-MADVANCEDRECORDS"

Note important . other way:
Code: [Select]
[0.055] Handling option "-MADVANCEDRECORDS"
[0.055] interpreting option "-MADVANCEDRECORDS"
[0.055] Handling option "-MOBJFPC"
[0.055] interpreting option "-MOBJFPC"
[0.055] Macro defined: FPC_OBJFPC

[2.359] Searching file Test_BTB_History.lpr... found
[2.359] (TEST_BTB_HISTORY) Load from TEST_BTB_HISTORY (implementation) unit U_TOOLS
[2.359] Test_BTB_History.lpr(19,1) (TEST_BTB_HISTORY) Parsing implementation of Test_BTB_History.lpr
[2.359] Test_BTB_History.lpr(23,3) Fatal: Syntax error, "identifier" expected but "TYPE" found
[2.477] Fatal: Compilation aborted
Order important.

I don't really understand these lines... does the compiler automatically define a macro "FPC_OBJFPC" when it encounters these options? I don't have an option "-MOBJFPC" defined, as far as I know the compiler gets "-Mfpc".

Thausand

  • Full Member
  • ***
  • Posts: 234
Re: "Note: passing compiler option -M twice with different values"
« Reply #5 on: April 07, 2019, 09:30:53 pm »
-Mresult was mentioned on this page: http://wiki.freepascal.org/User_Changes_2.6.0
Thank you. I read ... i not seen before.
Quote
Remedy: You can reenable the result alias by adding {$modeswitch result} to your program code (after any {$mode macpas} statements), or by using the -Mresult command line option (after any -Mmacpas parameter, and provided there are no {$mode xxx} directives in the source).
There also say order important.

I don't really understand these lines... does the compiler automatically define a macro "FPC_OBJFPC" when it encounters these options? I don't have an option "-MOBJFPC" defined, as far as I know the compiler gets "-Mfpc".
I sorry. It example i use for test  :).

first: fpc -va -MOBJFPC -MADVANCEDRECORDS Test_BTB_History.lpr
last: fpc -va -MADVANCEDRECORDS -MOBJFPC Test_BTB_History.lpr

Then see last try then OBJFPC last parameter and overwrite ADVANCEDRECORDS (mode objfpc no have advanced records)

If not know: lines are make with -va option
« Last Edit: April 07, 2019, 09:32:58 pm by Thausand »

lucamar

  • Hero Member
  • *****
  • Posts: 2144
Re: "Note: passing compiler option -M twice with different values"
« Reply #6 on: April 07, 2019, 09:41:08 pm »
I don't really understand these lines... does the compiler automatically define a macro "FPC_OBJFPC" when it encounters these options? I don't have an option "-MOBJFPC" defined, as far as I know the compiler gets "-Mfpc".

For some (indeed, most) modes and modeswicths the compiler defines some identifiers automatically and undefines some others. As for the ObjFPC, I supposse Thausand just used an example.

Order important.

A full mode change implies lots of "small mode" changes; that's why the order is important. In your example, -MOBJFPC automatically deactivates ADVANCEDRECORDS, no matter what you've done before setting the mode. That's why, for example, Lazarus starts programs with:
  {$mode objfpc}{$H+}
to make sure long-strings are on.
« Last Edit: April 07, 2019, 09:43:03 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

creaothceann

  • Full Member
  • ***
  • Posts: 109
Re: "Note: passing compiler option -M twice with different values"
« Reply #7 on: April 07, 2019, 09:48:48 pm »
For some (indeed, most) modes and modeswicths the compiler defines some identifiers automatically and undefines some others. As for the ObjFPC, I supposse Thausand just used an example.
OK... I just never saw log messages like that.

Do you know if there is an option to filter/deactivate that specific hint? I don't want to filter all of them. (Besides, now that we know that -M can be used several times, shouldn't the code generating that hint be removed/modified?)

EDIT: bug report submitted
« Last Edit: April 14, 2019, 10:42:02 pm by creaothceann »

PascalDragon

  • Hero Member
  • *****
  • Posts: 726
  • Compiler Developer
Re: "Note: passing compiler option -M twice with different values"
« Reply #8 on: April 16, 2019, 11:20:02 am »
For some (indeed, most) modes and modeswicths the compiler defines some identifiers automatically and undefines some others. As for the ObjFPC, I supposse Thausand just used an example.
OK... I just never saw log messages like that.
They are disabled by default and only visible when enabled using the -v<x> family of parameters.

Quote from: creaothceann link=topic=44963.msg316660#msg316660
Do you know if there is an option to filter/deactivate that specific hint? I don't want to filter all of them. (Besides, now that we know that -M can be used several times, shouldn't the code generating that hint be removed/modified?)

EDIT: bug report submitted
As mentioned in the bug report, this hint is generated by the Lazarus IDE itself, not by FPC.

Also please note that passing modeswitches on the command line might not be the best choice as they're reset if a {$mode xxx} is encountered in the code (or if a mode on the command line is passed after a modeswitch). It's safer to simply use an include file with the desired settings.