Compiler Hint: “Inline function '…' has not been expanded…”

后端 未结 4 1151
难免孤独
难免孤独 2021-02-19 05:06

In a unit I use the function DeleteFile and the compiler outputs a hint:

\"H2443 Inline function \'DeleteFile\' has not been expanded because

4条回答
  •  北海茫月
    2021-02-19 06:04

    Inline functions can be expanded inline. For example:

    function AddPlus(const A,B: Integer): Integer; inline;
    begin
      Result := A + B + 1;
    end;
    
    var
      x,y,z : Integer;
    begin
      y := 22;
      z := 11;
      x := AddPlus(y, z);
    end.
    

    Is rewritten to:

    var
      x,y,z : Integer;
    begin
      y := 22;
      z := 11;
      x := y+z+1;
    end.
    

    This removes the overhead of a function call.

    But in order to replace the call with the function body, the compiler needs more information, hence the complaint about the unit.

    Beware that not all inline functions are converted. Some are treated just like normal functions (its up to the compiler). Besides, inline is only needed at really tight performance bottlenecks.

提交回复
热议问题