### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: [solved] Question to Array of Char  (Read 5536 times)

#### Michl

• Full Member
• Posts: 226
##### [solved] Question to Array of Char
« on: June 02, 2014, 01:43:14 pm »
Hi,

I translate some wiki pages into German. I have a question to the topic http://wiki.lazarus.freepascal.org/Character_and_string_types#Array_of_Char.

Is the sentence
Quote
delivers: a b c d #0 since arrays are filled with null-bytes in Free Pascal
correct?!

I've made a test with different results:
Code: [Select]
`program Project1;const  aLength = 1000;type  TOldString1 = array[0..aLength] of Char;procedure test;type  TOldString2 = array[0..aLength] of Char;var  OldString1: TOldString1;  OldString2: TOldString2;  i: Integer;begin  for i:=0 to aLength do    if OldString1[i] <> #0 then      writeln('OldString1: ',Ord(OldString1[i]),' - [',i,']');  for i:=0 to aLength do    if OldString2[i] <> #0 then      writeln('OldString2: ',Ord(OldString2[i]),' - [',i,']');end;begin  test;  readln;end.`If the type "OldString" is declared in the procedure, the statement is false, otherwise seems to vote.

Here is already a little discussion: http://wiki.lazarus.freepascal.org/Talk:Character_and_string_types

The posted code as little project attached.
« Last Edit: June 02, 2014, 09:20:27 pm by Michl »
Code: [Select]
`type  TLiveSelection = (lsMoney, lsChilds, lsTime);  TLive = Array[0..1] of TLiveSelection;`

#### BigChimp

• Hero Member
• Posts: 5740
• Add to the wiki - it's free ;)
##### Re: Question to Array of Char
« Reply #1 on: June 02, 2014, 01:54:31 pm »
I think you already got an answer on the wiki talk page...

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

#### Michl

• Full Member
• Posts: 226
##### Re: Question to Array of Char
« Reply #2 on: June 02, 2014, 02:01:48 pm »
Yes of course, but I've made a lot of tests. The Array is all the time filled with #0!!!!!

Only when I declared it in the procedure, it is filled with different content.

That's why I wanted to hear some other opinions before I mistakenly change the statement.
Code: [Select]
`type  TLiveSelection = (lsMoney, lsChilds, lsTime);  TLive = Array[0..1] of TLiveSelection;`

#### howardpc

• Hero Member
• Posts: 3988
##### Re: Question to Array of Char
« Reply #3 on: June 02, 2014, 07:49:03 pm »
You should remove the incorrect statement in the wiki before translating.
There is much in software that happens to be true some of the time, such as the existence of zero bytes at many memory locations. Where this cannot be relied on (is not guaranteed by the compiler) it should not be stated falsely that this is a feature of Free Pascal.

#### Michl

• Full Member
• Posts: 226
##### Re: [solved] Question to Array of Char
« Reply #4 on: June 02, 2014, 09:27:20 pm »
Thank you, you've enlightened me!

I have now differentiated by static and dynamic array of char. If anyone want  to see, whether in terms of content and of the spelling (my English is not so good), is right: http://wiki.freepascal.org/Character_and_string_types#Array_of_Char

Thanks, and sorry for my rude behavior to ask twice
Code: [Select]
`type  TLiveSelection = (lsMoney, lsChilds, lsTime);  TLive = Array[0..1] of TLiveSelection;`