[fpc-devel] Bug or Feature? Inline of code from Units does not work when types uses in code are defined in implementation
Michael Ring
mail at michael-ring.org
Mon Apr 6 17:53:49 CEST 2015
Take the following unit, my goal is to have the code called in the unit
inlined in the main code.
This works fine when
type
pLongWord = ^LongWord;
is defined in the interface of the unit.
if this is defined in Implementation then Inlining of the code does not
work.
Is this correct behaviour? Or should both ways work?
Thank you,
Michael
Platform is arm-embedded, Compiler Commandline was:
/usr/local/lib/fpc/3.1.1/ppcrossarm -MObjFPC -Tembedded -Parm -Cparmv6m
-WpSTM32L053R8 -XParm-none-eabi- test.pas -a -g -B -Si
unit utest2;
{$inline on}
{$modeswitch advancedrecords}
interface
type
TBits_16 = 0..65535;
// Independent watchdog
TIWDG_KR_bits = record
private
function getKEY : TBits_16; inline;
procedure setKEY(value : TBits_16); inline;
public
property KEY : TBits_16 read getKEY write setKEY;// [0:15]
Key value (write only, read 0x0000)
end;
TIWDG_Registers = record
KR_bits : TIWDG_KR_bits;
KR : longWord; // 0x00 Key register
end;
const
IWDG_BASE = $40003000;
var
IWDG : TIWDG_Registers absolute IWDG_BASE;
//type
// pLongWord = ^LongWord;
implementation
type
pLongWord = ^LongWord;
function TIWDG_KR_bits.getKEY : TBits_16; inline;
begin
getKEY := pLongWord(@self)^ shr 0 and %1111111111111111;
end;
procedure TIWDG_KR_bits.setKEY(value : TBits_16); inline;
begin
pLongWord(@self)^ := pLongWord(@self)^ and
%11111111111111110000000000000000 or (value shl 0);
end;
end.
Calling Prog:
program test;
{$INLINE ON}
{$modeswitch advancedrecords}
uses
utest2;
var
a : longWord;
begin
IWDG.KR_bits.KEY := 1;
a := IWDG.KR_bits.KEY;
end.
More information about the fpc-devel
mailing list