On Fri, 30 Jun 2023, Michael Van Canneyt via fpc-pascal wrote:
On Fri, 30 Jun 2023, Hairy Pixels via fpc-pascal wrote:
On Jun 30, 2023, at 9:03 AM, Hairy Pixels <generic...@gmail.com> wrote:
That's why that worked. Hmm with short strings the null terminator could
be truncated when copying right? Something to look out for.
this is what I meant about truncation. S is no longer null terminated and
now the pchar will fail when passed to C libraries right?
var
s: String;
p: Pchar;
begin
s := 'hello';
p := @s;
S will still be null-terminated for ansistrings and shortstrings.
change to
s:=s+s;
p:=@s[1]; // and not @s
writeln(p[Length(s)+1]=#0);
this should have been p[Length(s)] obviously.
Michael.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal