Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-11

Zero terminated strings

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ABorka

Hi,

Are strings not zero terminated? I have a function declared:

function myfunc(s :String; i: Integer):String;

When going through the string "s" with asm instructions, it does not seem to have a zero byte at the end. Is this normal or something is not OK (maybe now with utf8 strings as defaults it is not there any longer)?

I got around this by doing a StrPCopy into a buffer of bytes, so just asking.

Thanks for any feedback

Reply by email

Vincent Snijders
to ABorka: Are strings not zero terminated? I have a function declared: function myfunc(s :String;…
ABorka wrote 9 lines
Hi, Are strings not zero terminated? I have a function declared: function myfunc(s :String; i: Integer):String; When going through the string "s" with asm instructions, it does not seem to have a zero byte at the end. Is this normal or something is not OK (maybe now with utf8 strings as defaults it is not there any longer)?
Are you sure that string = ansistring and not string = shortstring. Compile with
{$mode delphi} (=-MDelphi}, if porting from Delphi, else compile with {$H$} (=-sh).

Vincent

Reply by email

Michael Schnell
to ABorka: Are strings not zero terminated? I have a function declared: function myfunc(s :String;…
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

Reply by email