Difference between revisions of "Mode iso"

From Free Pascal wiki
Jump to navigationJump to search
(Spelling and minor grammar edits)
(title case of headers)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Mode_iso}}
+
{{Mode iso}}
  
Starting with version 3.0.2, the mode '''ISO 7185''' (switched on with '''{$mode iso}''' in source code or '''-Miso''' on the command line) of FPC complies with the requirements of level 0 and level 1 of ISO/IEC 7185. ISO 7185 is also known as [[Standard Pascal]].
+
[[FPC]]’s [[Compiler Mode|compatibility mode]] '''<syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">{$mode ISO}</syntaxhighlight>''' ''intends'' to comply with the requirements of level&nbsp;0 and&nbsp;1 of the ISO/IEC standard 7185.
 +
It became available in [[FPC New Features 2.6.0#Basic ISO Standard Pascal support|version 2.6.0]].
 +
The International Organization for Standardization standard 7185 is also known as [[Standard Pascal|Standard “Unextended” Pascal]].
  
Using mode iso has the following special features:
+
== Notable differences ==
 +
This list highlights differences to the standard [[Mode FPC|<syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">{$mode FPC}</syntaxhighlight>]] compiler compatibility mode.
 +
* <syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">{$modeSwitch ISOProgramParas+}</syntaxhighlight>: The [[Program|<syntaxhighlight lang="pascal" inline>program</syntaxhighlight>]] parameter list becomes significant. If not enabled via the <syntaxhighlight lang="bash" inline>‑MISO</syntaxhighlight> command-line switch, you will need to place <syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">{$mode ISO}</syntaxhighlight> ''before'' the <syntaxhighlight lang="pascal" inline>program</syntaxhighlight> header.
 +
* <syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">{$modeSwitch ISOIO+}</syntaxhighlight>: Files have associated “buffer variables” and [[Get|<syntaxhighlight lang="pascal" inline>get</syntaxhighlight>]] and [[Put|<syntaxhighlight lang="pascal" inline>put</syntaxhighlight>]] can operate on them. This functionality is not present in other modes.
 +
* <syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">{$modeSwitch ISOUnaryMinus+}</syntaxhighlight>: A unary [[Minus|minus]] has the same [[Operator#operator precedence|operator precedence]] as other addition operators. Usually ''all'' unary operators have the highest precedence.
 +
* <syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">{$modeSwitch ISOMod+}</syntaxhighlight>: The [[Mod|<syntaxhighlight lang="pascal" inline>mod</syntaxhighlight> operator]] yields a positive result (Euclidean-like definition).
 +
* <syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">{$modeSwitch nonLocalGoto+}</syntaxhighlight>: You can [[Goto|<syntaxhighlight lang="pascal" inline>goto</syntaxhighlight>]] labels anywhere in the program.
 +
* <syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">{$modeSwitch nestedProcVars+}</syntaxhighlight>: Procedural variables may assume addresses of nested [[Routine|routine]] definitions.
 +
* Support for routine parameters and <syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">{$modeSwitch classicProcVars+}</syntaxhighlight> (i.&#8239;e. no special syntax requirements to differentiate between routine activation and designation):<syntaxhighlight lang="pascal" line highlight="4,6,16">{$mode ISO}
 +
program routineParameter(output);
  
* External files are declared as parameters in the program statement.
+
procedure fancyPrint(function f: integer);
* Files have associated "buffer variables", and "get" and "put" procedures operate on them. This functionality is not present in other modes.
+
begin
* mod operation is as required by ISO Pascal.
+
writeLn('❧ ', f:1, ' ☙')
* Unary minus is as required by ISO Pascal.
+
end;
 +
 
 +
function getRandom: integer;
 +
begin
 +
{ chosen by fair dice roll: guaranteed to be random }
 +
getRandom := 4
 +
end;
 +
 
 +
begin
 +
fancyPrint(getRandom);
 +
end.</syntaxhighlight>
 +
 
 +
== Status ==
 +
* As of version 3.2.0 the FPC does not yet support conformant-array parameters, thus level&nbsp;1 requirements are not met, {{gitlab|issue|FPC|38632}}.
 +
* It is not possible to mix block-comment delimiters. <syntaxhighlight lang="pascal" inline style="whitespace: nowrap;">{ }</syntaxhighlight> and <syntaxhighlight lang="pascal" inline style="whitespace: nowrap;">(* *)</syntaxhighlight> cannot be mixed although the standard specifically states so.
 +
 
 +
== Notes ==
 +
* The mode’s intention is to ''at least'' compile an ISO-compliant <syntaxhighlight lang="pascal" inline>program</syntaxhighlight> [[Source code|source code]] file. The FPC will be able to compile a ''superset'' of programs.
 +
** For instance, ISO standard 7185 defines a ''fixed order'' of sections, [[Const#Const section|<syntaxhighlight lang="pascal" inline>const</syntaxhighlight>]]&nbsp;→ [[Type#custom type definitions|<syntaxhighlight lang="pascal" inline>type</syntaxhighlight>]]&nbsp;→ [[Var#Variable declaration section|<syntaxhighlight lang="pascal" inline>var</syntaxhighlight>]], but the FPC accepts ''any'' order, cf. {{gitlab|issue|FPC|37739}}.
 +
** Delphi-style [[Comments#Line comments|<syntaxhighlight lang="delphi" inline style="whitespace: nowrap;">// end-of-line comments</syntaxhighlight>]] are accepted.
 +
** Or the mere fact that procedural ''variables'' are allowed should be surprising enough.
 +
: It is quite possible that a ''different'' compiler rejects the same source code on grounds of non-compliance. Unlike the [[GNU Pascal]] Compiler there is no way to disable such “extensions”.
 +
* The value of the constant [[maxint|<syntaxhighlight lang="pascal" inline>maxInt</syntaxhighlight>]] is not necessarily identical to <syntaxhighlight lang="delphi" inline>high(ALUSInt)</syntaxhighlight>. The permissible range of values of the [[Integer|<syntaxhighlight lang="pascal" inline>integer</syntaxhighlight>]] data type still depends on the mode.

Latest revision as of 10:07, 21 January 2022

English (en) français (fr) русский (ru)

FPC’s compatibility mode {$mode ISO} intends to comply with the requirements of level 0 and 1 of the ISO/IEC standard 7185. It became available in version 2.6.0. The International Organization for Standardization standard 7185 is also known as Standard “Unextended” Pascal.

Notable differences

This list highlights differences to the standard {$mode FPC} compiler compatibility mode.

  • {$modeSwitch ISOProgramParas+}: The program parameter list becomes significant. If not enabled via the ‑MISO command-line switch, you will need to place {$mode ISO} before the program header.
  • {$modeSwitch ISOIO+}: Files have associated “buffer variables” and get and put can operate on them. This functionality is not present in other modes.
  • {$modeSwitch ISOUnaryMinus+}: A unary minus has the same operator precedence as other addition operators. Usually all unary operators have the highest precedence.
  • {$modeSwitch ISOMod+}: The mod operator yields a positive result (Euclidean-like definition).
  • {$modeSwitch nonLocalGoto+}: You can goto labels anywhere in the program.
  • {$modeSwitch nestedProcVars+}: Procedural variables may assume addresses of nested routine definitions.
  • Support for routine parameters and {$modeSwitch classicProcVars+} (i. e. no special syntax requirements to differentiate between routine activation and designation):
     1{$mode ISO}
     2program routineParameter(output);
     3
     4procedure fancyPrint(function f: integer);
     5begin
     6	writeLn('❧ ', f:1, ' ☙')
     7end;
     8
     9function getRandom: integer;
    10begin
    11	{ chosen by fair dice roll: guaranteed to be random }
    12	getRandom := 4
    13end;
    14
    15begin
    16	fancyPrint(getRandom);
    17end.
    

Status

  • As of version 3.2.0 the FPC does not yet support conformant-array parameters, thus level 1 requirements are not met, FPC issue 38632.
  • It is not possible to mix block-comment delimiters. { } and (* *) cannot be mixed although the standard specifically states so.

Notes

  • The mode’s intention is to at least compile an ISO-compliant program source code file. The FPC will be able to compile a superset of programs.
    • For instance, ISO standard 7185 defines a fixed order of sections, const → type → var, but the FPC accepts any order, cf. FPC issue 37739.
    • Delphi-style // end-of-line comments are accepted.
    • Or the mere fact that procedural variables are allowed should be surprising enough.
It is quite possible that a different compiler rejects the same source code on grounds of non-compliance. Unlike the GNU Pascal Compiler there is no way to disable such “extensions”.
  • The value of the constant maxInt is not necessarily identical to high(ALUSInt). The permissible range of values of the integer data type still depends on the mode.