Sign in Join

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

Mailing lists / fpc-pascal / 2003-12

char 0 in ansistrings

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Mark Emerson

Is it *absolutely safe* to include chr(0) in an ansistring and have it get treated like any other character? Or is there some instance where it will cause different behavior than other chars?

Mark

Reply by email

Jonas Maebe
to Mark Emerson
Mark Emerson wrote
Is it *absolutely safe* to include chr(0) in an ansistring and have it get treated like any other character? Or is there some instance where it will cause different behavior than other chars?

Only if you typecast your ansistring to a pchar.

Jonas

Reply by email

Mark Emerson
to Jonas Maebe

Jonas,

I'm afraid my question was unclear. Unfortunately, I asked two questions with opposite senses, and I don't know which one you answered. Please clarify which of my interpretations of your answer is what you intended:

(1) It is ONLY absolutely safe to include chr(0)....IF you typecast your ansistring to a pchar, and thus IF you treat it as an ansistring WITHOUT the typecast to pchar, it is NOT safe.

(2) It IS absolutely safe to include chr(0), UNLESS you typecast it to pchar...because typcasting to pchar is an INSTANCE (per my 2nd question) where it will cause different behavior...

Gimme a (1) or a (2). Thanks.

Mark

Show quoted text 15 lines
On 2 dec 2003, at 07:59, Mark Emerson wrote: >Is it *absolutely safe* to include chr(0) in an ansistring and have >it get treated like any other character? Or is there some instance >where it will cause different behavior than other chars? Only if you typecast your ansistring to a pchar. Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Jonas Maebe
to Mark Emerson
Mark Emerson wrote 14 lines
I'm afraid my question was unclear. Unfortunately, I asked two questions with opposite senses, and I don't know which one you answered. Please clarify which of my interpretations of your answer is what you intended: (1) It is ONLY absolutely safe to include chr(0)....IF you typecast your ansistring to a pchar, and thus IF you treat it as an ansistring WITHOUT the typecast to pchar, it is NOT safe. (2) It IS absolutely safe to include chr(0), UNLESS you typecast it to pchar...because typcasting to pchar is an INSTANCE (per my 2nd question) where it will cause different behavior... Gimme a (1) or a (2). Thanks.

(2) because in a pchar, #0 is an end-of-string marker.

Jonas

Reply by email