next up previous contents
Next: Global directives Up: Compiler directives Previous: Compiler directives

Local directives

  Local directives have no command-line counterpart. They influence the compiler's behaviour from the moment they're encountered until the moment another switch annihilates their behaviour, or the end of the unit or program is reached.

$F : Far or near functions

This directive is recognized for compatibility with Turbo Pascal. Under the 32-bit programming model, the concept of near and far calls have no meaning, hence the directive is ignored. A warning is printed to the screen, telling you so.

As an example, : the following piece of code :

{$F+}

Procedure TestProc;

begin
 Writeln ('Hello From TestProc');
end;

begin
 testProc
end.
Generates the following compiler output:
malpertuus: >pp -vw testf
Compiler: ppc386
Units are searched in: /home/michael;/usr/bin/;/usr/lib/ppc/0.9.1/linuxunits
Target OS: Linux
Compiling testf.pp
testf.pp(1) Warning: illegal compiler switch
7739 kB free
Calling assembler...
Assembled...
Calling linker...
12 lines compiled,
 1.00000000000000E+0000
You can see that the verbosity level was set to display warnings.

If you declare a function as Far (this has the same effect as setting it between {$F+}...{$F-} directives), the compiler also generates a warning :

testf.pp(3) Warning: FAR ignored

The same story is true for procedures declared as Near. The warning displayed in that case is:

testf.pp(3) Warning: NEAR ignored

$I : Input/Output checking

The {$I-} directive tells the compiler not to generate input/output checking code in your program. If you compile using the -Ci compiler switch, the Free Pascal compiler inserts input/output checking code after every input/output call in your program. If an error occurred during input or output, then a run-time error will be generated. Use this switch if you wish to avoid this behavior. If you still want to check if something went wrong, you can use the IOResult function to see if everything went without problems.

Conversely, {$I+} will turn error-checking back on, until another directive is encountered which turns it off again.

The most common use for this switch is to check if the opening of a file went without problems, as in the following piece of code:

...
assign (f,'file.txt');
{$I-}
rewrite (f);
{$I+}
if IOResult<>0 then
  begin
  Writeln ('Error opening file : "file.txt"');
  exit
  end;
...

$I : Include file

The {$I filename} directive tells the compiler to read further statements from the file filename. The statements read there will be inserted as if they occurred in the current file.

The compiler will append the .pp extension to the file if you don't specify an extension yourself. Do not put the filename between quotes, as they will be regarded as part of the file's name.

You can nest included files, but not infinitely deep. The number of files is restricted to the number of file descriptors available to the Free Pascal compiler.

Contrary to Turbo Pascal, include files can cross blocks. I.e. you can start a block in one file (with a Begin keyword) and end it in another (with a End keyword). The smallest entity in an include file must be a token, i.e. an identifier, keyword or operator.

$L : Link object file

The {$L filename} directive tells the compiler that the file filename should be linked to your program. You can only use this directive in a program. If you do use it in a unit, the compiler will not complain, but simply ignores the directive.

The compiler will not look for the file in the unit path. The name will be passed to the linker exactly as you've typed it.

Since the files name is passed directly to the linker, this means that on LINUX systems, the name is case sensitive, and must be typed exactly as it appears on your system.

Remark : Take care that the object file you're linking is in a format the linker understands. Which format this is, depends on the platform you're on. Typing ld on th command line gives a list of formats ld knows about.

You can pass other files and options to the linker using the -k command-line option. You can specify more than one of these options, and they will be passed to the linker, in the order that you specified them on the command line, just before the names of the object files that must be linked.

$I386_XXX : Specify assembler format

This switch informs the compiler what kind of assembler it can expect in an asm block. The XXX should be replaced by one of the following:

att
Indicates that asm blocks contain AT&T syntax assembler.
intel
Indicates that asm blocks contain Intel syntax assembler.
direct
Tells the compiler that asm blocks should be copied directly to the assembler file.

These switches are local, and retain their value to the end of the unit that is compiled, unless they are replaced by another directive of the same type. The command-line switch that corresponds to this switch is -R.

$MMX : MMX support

As of version 0.9.8, Free Pascal supports optimization for the MMX Intel processor (see also 7). This optimizes certain code parts for the MMX Intel processor, thus greatly improving speed. The speed is noticed mostly when moving large amounts of data. Things that change are

When MMX support is on, you aren't allowed to do floating point arithmetic. You are allowed to move floating point data, but no arithmetic can be done. If you wish to do floating point math anyway, you must first switch of MMX support and clear the FPU using the emms function of the cpu unit.

The following example will make this more clear:

Program MMXDemo;

uses cpu;

var
   d1 : double;
   a : array[0..10000] of double;
   i : longint;

begin
   d1:=1.0;
{$mmx+}
   { floating point data is used, but we do _no_ arithmetic }
   for i:=0 to 10000 do
     a[i]:=d2;  { this is done with 64 bit moves }
{$mmx-}
   emms;   { clear fpu }
   { now we can do floating point arithmetic }
   ....
end.
See, however, the chapter on MMX (7) for more information on this topic.

$OUTPUT_FORMAT : Specify the output format

{$OUTPUT_FORMAT format} has the same functionality as the -A command-line option : It tells the compiler what kind of object file must be generated. You can specify this switch only befor the Program or Unit clause in your source file. The different kinds of formats are shown in table (1.1).

  

Switch value Generated format
att AT&T assembler file.
o Unix object file.
obj OMF file.
wasm assembler for the Watcom assembler.
Table 1.1: Formats generated by the compiler

$V : Var-string checking

When in the + state, the compiler checks that strings passed as parameters are of the same, identical, string type as the declared parameters of the procedure.


next up previous contents
Next: Global directives Up: Compiler directives Previous: Compiler directives

Michael Van Canneyt
Tue Mar 31 16:50:06 CEST 1998