[fpc-devel]defines do not apply to units

miller at psy.otago.ac.nz miller at psy.otago.ac.nz
Thu Aug 8 00:02:26 CEST 2002


I am new to FreePascal, so please be tolerant
if this is a feature, but it looks like a bug to me.

The unexpected behavior is that {$Define Sym}
statements given in a main program do not stay
defined for a unit compiled in the same run.

Below is an example involving 3 very short files
to illustrate the problem.

When I compile and run the program TestDefs.Pas
with FreePascal v 1.0.6 on Win32, I expect the writelns
to say that the symbols are defined.  Instead, they
say that the symbols are undefined.

***Main program file: TestDefs.pas:

{$I TestDefs.Inc}

Program MyProg;

Uses TestUnit;

Begin
LargeMemCheck;
UseCRTCheck;
ProcPtrsCheck;
End.

***Include file with defines: TestDefs.Inc:
{$Define FPC}

{ Conditional defines for FreePascal (version 1.0.6): }
{$IfDef FPC}
{$Define LargeMem}
{$Define UseCRT}
{$Define ProcPtrs}
{$EndIf}

***Unit file: TestUnit.Pas:
Unit TestUnit;

Interface

Procedure LargeMemCheck;
Procedure UseCRTCheck;
Procedure ProcPtrsCheck;

Implementation

Procedure LargeMemCheck;
Begin
{$IfDef LargeMem}
Writeln('LargeMem is defined.');
{$Else}
Writeln('LargeMem is undefined.');
{$EndIf}
End;

Procedure UseCRTCheck;
Begin
{$IfDef UseCRT}
Writeln('UseCRT is defined.');
{$Else}
Writeln('UseCRT is undefined.');
{$EndIf}
End;

Procedure ProcPtrsCheck;
Begin
{$IfDef ProcPtrs}
Writeln('ProcPtrs is defined.');
{$Else}
Writeln('ProcPtrs is undefined.');
{$EndIf}
End;

End.

It is not difficult to work around (include the
defines file within each unit), but that seems a bit ugly.

Jeff Miller

jeffwin at psy.otago.ac.nz





More information about the fpc-devel mailing list