[fpc-devel] Zero terminated strings

Michael Schnell mschnell at lumino.de
Tue Nov 11 11:07:50 CET 2008


> Are strings not zero terminated?
They are not: a #0 is perfectly allowable character in a (long) string. 
That is why you can use strings for storing any kind of byte stream.
But they are: a #0 is automatically added at s[length(s)+1];

But accessing the terminating via string functions is erroneous.
But you can access it with

s: string
l: integer;
p: PChar;
c: char;

s := '123';
l := length(s);
p := pchar(s);
inc (p,l);
c := p^;


- Michael



More information about the fpc-devel mailing list