Sign in Join

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

Mailing lists / fpc-pascal / 2022-09

$modeswitch declared before $mode fails without warning

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Hairy Pixels

One more thing today working with closures. Declaring the modeswitch before the mode does not actually enable the feature and gives no warning. What happens then is basic syntax fails and you’re totally confused as to why.

Shouldn’t this be illegal or give a warning at least?

{$modeswitch functionreferences}
{$modeswitch anonymousfunctions}
{$mode objfpc}
program test;
var
  p: reference to procedure;
begin
end.

Regards,
Ryan Joseph

Florian Klämpfl
to Hairy Pixels
Hairy Pixels wrote 7 lines
One more thing today working with closures. Declaring the modeswitch before the mode does not actually enable the feature and gives no warning. What happens then is basic syntax fails and you’re totally confused as to why. Shouldn’t this be illegal or give a warning at least? {$modeswitch functionreferences} {$modeswitch anonymousfunctions} {$mode objfpc}

This is in general the case that $mode overrides all previously set switches i.e. it simply sets the switches as defined by the given mode so I am not sure if this is really worth a warning.

Show quoted text 13 lines
program test; var p: reference to procedure; begin end. Regards, Ryan Joseph _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Hairy Pixels
to Florian Klämpfl
On Sep 18, 2022, at 7:37 PM, Florian Klämpfl via fpc-pascal wrote: This is in general the case that $mode overrides all previously set switches i.e. it simply sets the switches as defined by the given mode so I am not sure if this is really worth a warning.

Is there ever a time where this would be useful to put a mode switch before the mode? I always think about it like a 2 step process: 1) choose the mode and 2) add extra features via mode switches. Unless I’m missing some use case it just seems like a way to create bugs.

Regards,
Ryan Joseph

Sven Barth
to Hairy Pixels
Hairy Pixels wrote 5 lines
> On Sep 18, 2022, at 7:37 PM, Florian Klämpfl via fpc-pascal wrote: > > This is in general the case that $mode overrides all previously set switches i.e. it simply sets the switches as defined by the given mode so I am not sure if this is really worth a warning. Is there ever a time where this would be useful to put a mode switch before the mode? I always think about it like a 2 step process: 1) choose the mode and 2) add extra features via mode switches. Unless I’m missing some use case it just seems like a way to create bugs.

The thing is that it is not necessary to use a mode directive. Either the user might be happy with the default mode FPC and just add some modeswitch for extended functionality or the mode might be provided as a command line parameter again with adding some special functionality.

And it would be much more effort to keep track of when a modeswitch directive was used in case a mode directive is used later on. Just not worth the effort as it's documented that a mode directive resets any modeswitches.

Regards,
Sven