Recent

Author Topic: Code reuseability  (Read 1005 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 6283
  • Compiler Developer
Re: Code reuseability
« Reply #15 on: November 24, 2025, 09:58:04 pm »
A direct wish for extended compiler functionality.
In certain scenarios, a lot of code is identical between procedures and functions, but unless making a file and using {$I FileName}, the code have to be written double up, or even more than double up.
I would like to suggest a similar pattern of {$Region 'Name'} and {$EndRegion}:
Code: Pascal  [Select][+][-]
  1. {$CodeBlock 'Name'}
  2.   // Code for identical reuse here...
  3. {$EndCodeBlock}

And then later where you want to insert that exact codeblock on compiletime:
Code: Pascal  [Select][+][-]
  1. Procedure SomeFunctionality(...);
  2.   Var
  3.      Something:Integer;
  4.   Begin
  5.     Something := High(MyArray);
  6.    {$ReuseCodeBlock 'Name'}
  7.   End;

No. Use $Include directives for that or extract the code into subroutines.

My problem is that I have already tried that, I made a wrapper, but I want the code to be inlined as well, and the compiler refuse to do inlining on 3 generic functions when one is referencing another.

The compiler needs to know the body of a function before it can inline it. Thus if you have two functions calling each other then one will not be inlined.

 

TinyPortal © 2005-2018