Sign in Join

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

Mailing lists / fpc-pascal / 2011-02

String and dynamic array initialisation

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Mark Morgan Lloyd

Are there any cases where a string variable will be allocated with anything other than zero length, or a dynamic array will be allocated with anything other than zero elements?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Jonas Maebe
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote
Are there any cases where a string variable will be allocated with anything other than zero length,

In case it's a shortstring, the initial data could be anything.

or a dynamic array will be allocated with anything other than zero elements?

No.

Jonas

Mark Morgan Lloyd
to Jonas Maebe: In case it's a shortstring, the initial data could be anything. No. Jonas
Jonas Maebe wrote 11 lines
On 10 Feb 2011, at 16:21, Mark Morgan Lloyd wrote: > Are there any cases where a string variable will be allocated with > anything other than zero length, In case it's a shortstring, the initial data could be anything. > or a dynamic array will be allocated with anything other than zero > elements? No.

Thanks Jonas, it was mainly the dynamic array case that I was interested in. Presumably a string defined without an explicit length is a longstring and starts empty.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Jonas Maebe
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote
Presumably a string defined without an explicit length is a longstring

Only in case of {$h+} (which is the default in Delphi mode, but not in other modes).

and starts empty.

Yes.

Jonas