[fpc-devel] bug or feature - more

2022-02-12 Thread Martin Frb via fpc-devel

Should the below then work? (It currently does)

Note, using "TBar = class end;" inside TFoo => does not work (expected). 
It creates a type TFoo.TBar.


But the "type Abc = TBar"  >imports< the outer forward declaration.
Btw, the compiler also does not care which of the 2 procedure 
declarations is used.



program Project1;

type
  TBar = class;

  Tfoo =  class
    type Abc = TBar;

    Abc = class
  procedure Sub;
    end;
  end;

{ Tfoo.Abc }

//procedure TBar.Sub;
procedure Tfoo.Abc.Sub;
begin
end;

begin
  TBar.Create.Sub;
end.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Bug or Feature? Inline of code from Units does not work when types uses in code are defined in implementation

2015-04-06 Thread Michael Ring

Thanks,

So do you think it is worth to extend documentation for inline? Or 
perhaps the compiler could give a warning when code is not suitable for 
inlining or is this decision done when a caller requests inlining and 
not when the inline function gets compiled?


Michael

Am 06.04.15 um 18:59 schrieb Florian Klaempfl:

Am 06.04.2015 um 17:53 schrieb Michael Ring:

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?

Inline is only a recommendation to the compiler. Such a definition in
the implementation part prevents indeed inlining.

In this particular case I recommend that you just leave the definition
away so compiler uses that one of the system unit.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Bug or Feature? Inline of code from Units does not work when types uses in code are defined in implementation

2015-04-06 Thread Florian Klämpfl
Am 06.04.2015 um 19:23 schrieb Michael Ring:
 Thanks,
 
 So do you think it is worth to extend documentation for inline? Or perhaps 
 the compiler could give a
 warning when code is not suitable for inlining or is this decision done when 
 a caller requests
 inlining and not when the inline function gets compiled?

If the situation is clear, the compiler gives a hint. In this case, the 
procedure is inlined if it
is called in the same unit, otherwise not.

The decision, if a procedure can be inlined is pretty difficult and changes 
also from time to time,
so I prefer neither to document (situation might change and documentation gets 
wrong) it nor
increase the hints regarding this (sometimes it is really hard to explain why 
something is not inlined).
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Bug or Feature? Inline of code from Units does not work when types uses in code are defined in implementation

2015-04-06 Thread Michael Ring
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 0x)

  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 %;
end;

procedure TIWDG_KR_bits.setKEY(value : TBits_16); inline;
begin
  pLongWord(@self)^ := pLongWord(@self)^ and 
% 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.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Bug or Feature? Inline of code from Units does not work when types uses in code are defined in implementation

2015-04-06 Thread Florian Klaempfl
Am 06.04.2015 um 17:53 schrieb Michael Ring:
 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?

Inline is only a recommendation to the compiler. Such a definition in
the implementation part prevents indeed inlining.

In this particular case I recommend that you just leave the definition
away so compiler uses that one of the system unit.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] bug or feature?

2013-11-24 Thread Sergei Gorelkin

25.11.2013 3:31, Paul Ishenin пишет:

22.11.2013 23:09, Sergei Gorelkin пишет:

Hello together,

The following compiles and executes correctly in objfpc mode (and rejected by 
Delphi and by FPC in
mode Delphi). Is implicit taking address of array there by design?

Yes, it is a FPC feature which is widely used by Lazarus.


This is good to know, thanks!

Sergei


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


[fpc-devel] bug or feature?

2013-11-22 Thread Sergei Gorelkin

Hello together,

The following compiles and executes correctly in objfpc mode (and rejected by Delphi and by FPC in 
mode Delphi). Is implicit taking address of array there by design?


type
  PReal = ^Real;
const
  xa: array[0..3] of Real = (1.0,2.0,3.0,4.0);

procedure test(x: PReal);
begin
  writeln(x[3]);
end;

begin
  test(xa);   // prints 4.0e+0
end.

Regards,
Sergei
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel