Using any {$modeswitch xxx} overrides -Sh as specified on the command line
Original Reporter info from Mantis: Michalis @michaliskambi
-
Reporter name: Michalis Kamburelis
Original Reporter info from Mantis: Michalis @michaliskambi
- Reporter name: Michalis Kamburelis
Description:
As far as I understand, the purpose of modeswitch is to change a particular syntax behavior --- without touching any other behavior. But it seems that using {
modeswitch nestedprocvars} also implicitly changes the state of $H switch: it makes string=ShortString (which is probably something you seldom want in modern code).
Compiling the attached testcase with -Sh:
$ fpc -Mobjfpc -Sh nestedprocvars_string.pas
$ ./nestedprocvars_string
255
aaaa....
Adding {$H+} in the source code (after or before {$modeswitch nestedprocvars}) makes it work Ok: string remains equal to AnsiString. The testcase then correctly prints 1000 and 'a' * 1000.
On the command-line, -Mnestedprocvars also seems to activate shortstrings, this time only if it's after -Sh. So if you remove {$modeswitch nestedprocvars} from the attached testcase, and try
fpc -Mobjfpc -Sh -Mnestedprocvars nestedprocvars_string.pas
then string=ShortString. But
fpc -Mobjfpc -Mnestedprocvars -Sh nestedprocvars_string.pas
is correct: string remains AnsiString.
I think it would be cleaner if -Mnestedprocvars and {$modeswitch nestedprocvars} just didn't touch the state of $H at all. These two features (longstrings and nested procs) seem completely unrelated and orthogonal.
Tested with FPC 2.6.0 and 2.7.1 (SVN state from 2012-04-22, revision 20993).
Mantis conversion info:
- Mantis ID: 21951
- OS: Debian GNU/Linux
- OS Build: (testing)
- Platform: i386
- Fixed in revision: 21247 (#50d2fa71)