Difference between revisions of "Hint Directives"

From Free Pascal wiki
Jump to navigationJump to search
m
m (fix fixation of syntaxhighlight)
 
(One intermediate revision by one other user not shown)
Line 18: Line 18:
  
 
The following are examples:
 
The following are examples:
<syntaxhighlight>
+
<syntaxhighlight lang="pascal">
Const
+
Const
   AConst = 12 deprecated;
+
   AConst = 12 deprecated;
+
 
var
+
var
   p : integer platform;
+
   p : integer platform;
+
 
Function Something : Integer; experimental;
+
Function Something : Integer; experimental;
+
 
begin
+
begin
   Something:=P+AConst;
+
   Something:=P+AConst;
end;
+
end;
+
 
begin
+
begin
   Something;
+
   Something;
 
end.
 
end.
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
This would result in the following output:
 
This would result in the following output:
<syntaxhighlight>
+
<syntaxhighlight lang="text">
testhd.pp(11,15) Warning: Symbol "p" is not portable
+
testhd.pp(11,15) Warning: Symbol "p" is not portable
testhd.pp(11,22) Warning: Symbol "AConst" is deprecated
+
testhd.pp(11,22) Warning: Symbol "AConst" is deprecated
 
testhd.pp(15,3) Warning: Symbol "Something" is experimental
 
testhd.pp(15,3) Warning: Symbol "Something" is experimental
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
Hint directives can follow all kinds of identifiers: units, constants, types, variables, functions, procedures and methods.
 
Hint directives can follow all kinds of identifiers: units, constants, types, variables, functions, procedures and methods.
 
[[Category:FPC]]
 
[[Category:Directives]]
 

Latest revision as of 05:18, 23 June 2020

English (en) suomi (fi) français (fr)

Using Hint Directives

Whenever an identifier marked with a hint directive is later encountered by the compiler, then a warning will be displayed, corresponding to the specified hint.

  • deprecated
    • The use of this identifier is deprecated, use an alternative instead. The deprecated keyword can be followed by a string constant with a message. The compiler will show this message whenever the identifier is encountered.
  • experimental
    • The use of this identifier is experimental: this can be used to flag new features that should be used with caution.
  • platform
    • This is a platform-dependent identifier: it may not be defined on all platforms.
  • unimplemented
    • This should be used on functions and procedures only. It should be used to signal that a particular feature has not yet been implemented.

The following are examples:

Const
  AConst = 12 deprecated;

var
  p : integer platform;

Function Something : Integer; experimental;

begin
  Something:=P+AConst;
end;

begin
  Something;
end.

This would result in the following output:

testhd.pp(11,15) Warning: Symbol "p" is not portable
testhd.pp(11,22) Warning: Symbol "AConst" is deprecated
testhd.pp(15,3) Warning: Symbol "Something" is experimental

Hint directives can follow all kinds of identifiers: units, constants, types, variables, functions, procedures and methods.