Difference between revisions of "Mode ObjFPC"

From Free Pascal wiki
Jump to navigationJump to search
(modeswitch)
Line 1: Line 1:
 
{{Mode ObjFPC}}
 
{{Mode ObjFPC}}
  
The mode '''ObjFPC''', switched on with <syntaxhighlight lang="pascal" enclose="none">{$mode objfpc}</syntaxhighlight> in source code, or <code>-Mobjfpc</code> on the command line, is the default mode for [[Lazarus]] source files (the default compiler mode when not using Lazarus is [[Mode FPC|FPC mode]]).
+
The mode '''ObjFPC''', switched on with <syntaxhighlight lang="pascal" enclose="none">{$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:
Line 8: Line 8:
 
# A [[Forward|forward declaration]] must be repeated exactly the same by the [[Implementation|implementation]] of a [[Function|<syntaxhighlight lang="pascal" enclose="none">function</syntaxhighlight>]]/[[Procedure|<syntaxhighlight lang="pascal" enclose="none">procedure</syntaxhighlight>]]. In particular,  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" enclose="none">function</syntaxhighlight>]]/[[Procedure|<syntaxhighlight lang="pascal" enclose="none">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 [[Integer|type <syntaxhighlight lang="pascal" enclose="none">integer</syntaxhighlight>]] is redefined as [[Longint|<syntaxhighlight lang="pascal" enclose="none">longint</syntaxhighlight>]].
 
# The [[Objpas]] unit is loaded right after the system unit. One of the consequences of this is that the [[Integer|type <syntaxhighlight lang="pascal" enclose="none">integer</syntaxhighlight>]] is redefined as [[Longint|<syntaxhighlight lang="pascal" enclose="none">longint</syntaxhighlight>]].
 
# The [[Cvar|<syntaxhighlight lang="pascal" enclose="none">cvar</syntaxhighlight>]] type may be used.
 
# The [[Cvar|<syntaxhighlight lang="pascal" enclose="none">cvar</syntaxhighlight>]] type may be used.
Line 14: Line 14:
 
# 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|<syntaxhighlight lang="pascal" enclose="none">shortstring</syntaxhighlight>s]] by default. This may be changed by using the <code>-Sh</code> command line switch or the <syntaxhighlight lang="pascal" enclose="none">{$H+}</syntaxhighlight> switch.
 
# Strings are [[Shortstring|<syntaxhighlight lang="pascal" enclose="none">shortstring</syntaxhighlight>s]] by default. This may be changed by using the <code>-Sh</code> command line switch or the <syntaxhighlight lang="pascal" enclose="none">{$H+}</syntaxhighlight> switch.
# [[Exception|Exceptions]], [[Class|classes]] and [[Interfaces]] are enabled.
+
# [[Exceptions|Exceptions]], [[Class|classes]] and [[Interfaces]] are enabled.

Revision as of 21:34, 12 June 2019

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.