Recent

Author Topic: Note from ide when adding a object in a TFPGObjectlist  (Read 377 times)

JohnKuiper

  • New member
  • *
  • Posts: 7
Note from ide when adding a object in a TFPGObjectlist
« on: August 12, 2024, 11:29:23 am »
Wat is this message mean:
Quote
note: call to subroutine "function TFPGObjectlist<objkeurmeesteruitslag.TRasPerkeurmeester>.Add(const item : TRasPerKeuster) longint;" marked as inline is not inlined
And why is the function using a const in the parameter?
Isn't an object aleady a pointer or wil it copied the pointer reference to a local parameter when not using 'const' ?

TRon

  • Hero Member
  • *****
  • Posts: 3234
Re: Note from ide when adding a object in a TFPGObjectlist
« Reply #1 on: August 12, 2024, 11:35:44 am »
Wat is this message mean:
Quote
note: call to subroutine "function TFPGObjectlist<objkeurmeesteruitslag.TRasPerkeurmeester>.Add(const item : TRasPerKeuster) longint;" marked as inline is not inlined
See also reference manual inline. The compiler indicates that it was unable to follow the hint to inline the code during compilation.

Quote
And why is the function using a const in the parameter?
Isn't an object aleady a pointer or wil it copied the pointer reference to a local parameter when not using 'const' ?
See also reference manual constant parameters. It is an agreement that the called routine will not change the contents of the parameter. If the called routine disobeys then the compiler will complain about it.

edit: example
Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. {$mode objfpc}
  4.  
  5. procedure Hitme(const x: pointer);
  6. begin
  7.   x := nil;
  8. end;
  9.  
  10. begin
  11.   HitMe(@Hitme);
  12. end.
  13.  

the compiler barfs:
Code: [Select]
Free Pascal Compiler version 3.2.2 [2021/05/16] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling test.pas
test.pas(7,3) Error: Can't assign values to const variable
test.pas(12,4) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
« Last Edit: August 12, 2024, 11:40:40 am by TRon »
All software is open source (as long as you can read assembler)

Thaddy

  • Hero Member
  • *****
  • Posts: 15641
  • Censorship about opinions does not belong here.
Re: Note from ide when adding a object in a TFPGObjectlist
« Reply #2 on: August 12, 2024, 12:32:52 pm »
const generates more optimal code if it adheres to the the rule that the parameter will not be changed inside the procedure or function. This is especially the case with parameters of a managed type:strings, classes, advanced records etc. because the compiler knows it can skip reference counting code. But it can also be beneficial with simple types: depending on the complexity of the code it can save a register and/or a copy
« Last Edit: August 12, 2024, 12:42:02 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018