Reputation: 27493
The next application
program Project1;
{$IFDEF FPC}
{$mode delphi}
{$ENDIF}
begin
{$IFDEF CPU386}
Writeln('CPU386');
{$ENDIF}
Readln;
end.
produce different output in Delphi(XE) and FPC(2.6.2) on my system (Win7 64 bit, CPU intel core i3). Delphi outputs CPU386
string, FPC does not.
Seems like FPC does not define CPU386
symbol for my CPU (see the list of FPC defines); it defines CPUX86_64
symbol instead.
So far I am using the next workaround:
{$IFDEF FPC}
{$IFNDEF CPU386}
{$IFDEF CPUX86_64}
{$DEFINE CPU386}
{$ENDIF}
{$ENDIF}
{$ENDIF}
Upvotes: 2
Views: 914
Reputation: 26356
Easiest is to look in FPC's "fpc -va output to see what a (32-bit) FPC would define on i386: (2.6.0)
[0.002] Macro defined: CPU86
[0.002] Macro defined: CPU87
[0.002] Macro defined: CPU386
[0.002] Macro defined: CPUI386
[0.002] Macro defined: CPU32
A 64-bit compiler defines: (2.7.1, didn't have a release version at hand)
[0.004] Macro defined: CPUX86_64
[0.004] Macro defined: CPUAMD64
[0.004] Macro defined: CPU64
[0.004] Macro defined: CPUX64
It is a pity that Delphi didn't choose compatible defines. Since the x86_64 architecture has been renamed several time, FPC defines several.
Note btw that CPU32 and CPU64 are for general 32/64-bit switching. Use this for anything that affects only pointer size but is not x86 specific. While originally mostly to abstract between Intel and PowerPC, with 64-bit ARM coming this because important again.
The cpui386 and cpux86_64 for changes that really target a specific processor.
The manual for these defines is here
Upvotes: 1
Reputation: 612954
That is as expected. The CPU386
conditional is for 32 bit Intel x86 targets. The CPUX86_64
conditional is for 64 bit Intel x64 targets.
When you compile your program with the 64 bit Delphi compiler, it does not produce any output either. Because the CPU386
conditional is not defined for the 64 bit Delphi compiler either.
It is incorrect to do this:
{$IFDEF CPUX86_64}
{$DEFINE CPU386}
{$ENDIF}
The CPU386
means that the target architecture is 32 bit Intel x86. And 64 bit Intel x64 is not.
The Delphi documentation for predefined conditionals is here: http://docwiki.embarcadero.com/RADStudio/en/Conditional_compilation_(Delphi)#Predefined_Conditionals
It lists the following under the CPU heading:
For 32 bit x86 targets Delphi and FPC both define CPU386
. For 64 bit x64 targets Delphi defined CPUX64
and FPC defines CPUX86_64
.
If you need to use common conditionals across shared source code then you will likely need to do some extra work. Suppose that you settle on CPUX86
and CPUX64
. Then you would include this:
{$IFDEF FPC}
{$IFNDEF CPU386}
{$DEFINE CPUX86}
{$ENDIF}
{$IFNDEF CPUX86_64}
{$DEFINE CPUX64}
{$ENDIF}
{$ENDIF}
Upvotes: 2