Autor Téma: chyba použití inline  (Přečteno 1945 krát)

Offline JaroB

  • Guru
  • *****
  • Příspěvků: 1144
  • Karma: 29
    • Verze Delphi: XE8, Sydney
chyba použití inline
« kdy: 18-09-2012, 09:23:06 »
Rád bych upozornil na chybu v použití inline, která vede na chybu resp. varování ([DCC Warning] Unit1.pas(570): H2135 FOR or WHILE loop executes zero times - deleted), tato chyba je způsobena použitím inline tam, kde jsou interní odkazy na jiné (ne-inlinovatelné) funkce (nebo se jedná o vnitřní funkci v metodě) viz typický příklad:
Kód: Delphi [Vybrat]
  1.     {Copy of the part of the RALib}
  2.     function SubStr(const S: string; const index: integer; const Separator: string): string; //cannot be inline !!!
  3.     var
  4.       i: integer;
  5.       pB, pE: PChar;
  6.     begin
  7.       Result := '';
  8.       if ((index < 0) or ((index = 0) and (Length(S) > 0) and (S[1] = Separator))) or (Length(S) = 0) then
  9.         Exit;
  10.       pB := PChar(S);
  11.       for i := 1 to index do
  12.       begin
  13.         pB := StrPos(pB, PChar(Separator));
  14.         if pB = nil then exit;
  15.         pB := pB + Length(Separator);
  16.         if pB[0] = #0 then exit;
  17.       end;
  18.       pE := StrPos(pB + 1, PChar(Separator));
  19.       if pE = nil then pE := PChar(S) + Length(S);
  20.       if not (AnsiStrLIComp(pB, PChar(Separator), Length(Separator)) = 0) then
  21.         SetString(Result, pB, pE - pB);
  22.     end;
  23.  
Delphi 2005 toto nezkousne, ale vyšší verze už ano s warningem.