Difference between revisions of "Mode ObjFPC"

From Free Pascal wiki
Jump to navigationJump to search
m (fix typo)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Mode_ObjFPC}}
+
{{Mode ObjFPC}}
  
The mode '''ObjFPC''', switched on with '''{$mode objfpc}''', is the default mode for [[Lazarus]] source files.
+
The mode '''ObjFPC''', switched on with <syntaxhighlight lang="pascal" inline>{$mode objfpc}</syntaxhighlight> in [[Source_code|source code]], or <code>-Mobjfpc</code> on the [[Command-line interface|command line]], is the default mode for [[Lazarus]] source files (the default [[Compiler Mode|compiler mode]] when not using Lazarus is [[Mode FPC|FPC mode]]).
  
 
Using the ObjFPC mode has the following consequences:
 
Using the ObjFPC mode has the following consequences:
  
#The address operator has to be used to assign procedural variables.
+
# The [[@|address operator]] has to be used to assign procedural variables. Use <syntaxhighlight lang="pascal" inline>{$modeswitch classicProcVars+}</syntaxhighlight> to disable this requirement.
#A [[Forward|forward]] declaration must be repeated exactly the same by the [[Implementation]] of a [[Function|function]]/[[Procedure|procedure]]. In particular, the parameters cannot be omitted when implementing the function or procedure, and the calling convention must be repeated as well.
+
# A [[Forward|forward declaration]] must be repeated exactly the same by the [[Implementation|implementation]] of a [[Function|<syntaxhighlight lang="pascal" inline>function</syntaxhighlight>]]/[[Procedure|<syntaxhighlight lang="pascal" inline>procedure</syntaxhighlight>]]. In particular, parameters cannot be omitted when implementing the function or procedure, and the calling convention must be repeated as well.
#[[Overload|Overloading]] of functions is allowed.
+
# [[Overload|Overloading]] of functions is allowed.
#Nested comments are allowed.
+
# Nested [[Comments|comments]] are allowed.
#The [[Objpas]] unit is loaded right after the system unit. One of the consequences of this is that the type Integer is redefined as [[Longint]].
+
# The [[Objpas]] unit is loaded right after the system unit. One of the consequences of this is that the [[Integer|type <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight>]] is redefined as [[Longint|<syntaxhighlight lang="pascal" inline>longint</syntaxhighlight>]].
#The [[Cvar|cvar]] type may be used.
+
# The [[Cvar|<syntaxhighlight lang="pascal" inline>cvar</syntaxhighlight>]] type may be used.
#[[PChar]]s are converted to [[String|string]]s automatically.
+
# [[PChar|<syntaxhighlight lang="pascal" inline>PChar</syntaxhighlight>]]s are converted to [[String|<syntaxhighlight lang="pascal" inline>string</syntaxhighlight>s]] automatically.
#Parameters in class methods cannot have the same names as class properties.
+
# Parameters in class methods cannot have the same names as class properties.
#Strings are [[Shortstring]]s by default. This may be changed by using the -Sh command line switch or the {$H+} switch.
+
# Strings are [[Shortstring|<syntaxhighlight lang="pascal" inline>shortstring</syntaxhighlight>s]] by default. This may be changed by using the <code>-Sh</code> command line switch or the <syntaxhighlight lang="pascal" inline>{$H+}</syntaxhighlight> switch.
#[[Exception|Exceptions]], [[Class|Classes]] and [[Interfaces]] are enabled.
+
# [[Exceptions|Exceptions]], [[Class|classes]] and [[Interfaces]] are enabled.
 +
# Inline code is allowed: There is no need to enable it with the <syntaxhighlight lang="pascal" inline>{$INLINE}</syntaxhighlight> directive.

Latest revision as of 17:11, 6 August 2022

English (en) español (es) français (fr)

The mode ObjFPC, switched on with {$mode objfpc} in source code, or -Mobjfpc on the command line, is the default mode for Lazarus source files (the default compiler mode when not using Lazarus is FPC mode).

Using the ObjFPC mode has the following consequences:

  1. The address operator has to be used to assign procedural variables. Use {$modeswitch classicProcVars+} to disable this requirement.
  2. A forward declaration must be repeated exactly the same by the implementation of a function/procedure. In particular, parameters cannot be omitted when implementing the function or procedure, and the calling convention must be repeated as well.
  3. Overloading of functions is allowed.
  4. Nested comments are allowed.
  5. The Objpas unit is loaded right after the system unit. One of the consequences of this is that the type integer is redefined as longint.
  6. The cvar type may be used.
  7. PChars are converted to strings automatically.
  8. Parameters in class methods cannot have the same names as class properties.
  9. Strings are shortstrings by default. This may be changed by using the -Sh command line switch or the {$H+} switch.
  10. Exceptions, classes and Interfaces are enabled.
  11. Inline code is allowed: There is no need to enable it with the {$INLINE} directive.