Question:

Question:
In Delphi Tokyo AnsiStrings.StrLen(const Str: PAnsiChar): Cardinal; is implemented as Result := Length(Str);
This results in a call to System._PCharLen.

Is the use of the Length function with PAnsiChar and PChar documented? Has it always been there?

Comments

  1. fpc supports this use of length and it is documented. freepascal.org - Length
    "Length also supports arguments of type PCharand PWideChar, in which case it is identical to the StrLen and WStrLen functions, respectively."

    ReplyDelete
  2. Kiriakos Vlahos I didn't claim there was an implicit cast, I said the answer to the questions, 'Is the use of the Length function with PAnsiChar and PChar documented?' and 'Has it always been there?' are positive irrespective of special handling by the Length implementation itself, given how assigning a PChar to a string without any special syntax is part of the language.

    That said... as your 'real' question (I think) is on the Length implementation specifically, I've just checked XE2, and explicit support (without relying on an implicit cast) is there too, for both PAnsiChar and PWideChar. I'm pretty sure this wasn't part of the 90s and early 00s releases, but I don't have any older version still around to check.

    ReplyDelete
  3. Chris Rolliston That's great. Thanks! So it is a documentation bug. Fpc is quite explicit about it.

    ReplyDelete

Post a Comment