Difference between revisions of "Talk:Character and string types"

From Lazarus wiki
Jump to navigationJump to search
m
Line 40: Line 40:
 
: [[User:Jonas|Jonas]] 11:37, 2 June 2014 (CEST)
 
: [[User:Jonas|Jonas]] 11:37, 2 June 2014 (CEST)
  
::Thank you for your comment! I think, its maybe a bug, cause if the type "OldString" is declared in the procedure, the statement is false, otherwise it seems to be true. I asked in the [http://forum.lazarus.freepascal.org/index.php/topic,24744.0.html forum].
+
::Thank you for your comment! I think, its maybe a bug, cause if the type "OldString" is declared in the procedure, the statement is false, otherwise seems to vote. I asked in the [http://forum.lazarus.freepascal.org/index.php/topic,24744.0.html forum].
 
::--[[User:Michl|Michl]] 13:46, 2 June 2014 (CEST)
 
::--[[User:Michl|Michl]] 13:46, 2 June 2014 (CEST)
 +
 +
:::All global variables are always initialised with 0/#0/nil/... That is documented in the manual, has nothing to do with array of char, and should therefore not be mentioned here because it is orthogonal.
 +
:::[[User:Jonas|Jonas]] 14:43, 2 June 2014 (CEST)

Revision as of 14:43, 2 June 2014

Doesn't ANSIChar contain an ANSI character instead of ASCII? I.e. it is codepage dependent but can contain byte values 0..255?

--BigChimp 15:28, 28 December 2013 (CET)

This is the information of the official FPC documentation. I will do additional research.
--Jwdietrich 15:33, 28 December 2013 (CET)
Yes, I suspect the official FPC documentation is wrong/incomplete ;)
BTW: thanks for writing this page - it's very helpful!
--BigChimp 16:53, 28 December 2013 (CET)
Thanks for your positive feedback. In fact, it is ANSI. Although the official Free Pascal documentation states that a char contains an ASCII character, is is stored as a byte to use extended ASCII or ANSI.
--Jwdietrich 16:55, 28 December 2013 (CET)


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

I've tested (Lazarus 1.2.2 r44758 FPC 2.6.4 i386-win32-win32/win64 and Lazarus 1.3 r45097M FPC 2.7.1 i386-win32-win32/win64 on Win7)

procedure TForm1.Button1Click(Sender: TObject);
type
  TOldString4 = array[0..4] of char;
var
  aOldString4: TOldString4;
begin
  aOldString4[0] := 'a';
  aOldString4[1] := 'b';
  aOldString4[2] := 'c';
  aOldString4[3] := 'd';
  writeln('['+aOldString4[4]+']');
  Caption:=IntToStr(ord(aOldString4[4]));
end;

I got different results, but not #0 for aOldString4[4]. So, do I have to update the facts or do I missunderstood the statement?

Thanks --Michl 23:10, 1 June 2014 (CEST)

That statement is indeed completely bogus, there is no guarantee whatsoever regarding the content of that array element. Maybe the author was confused because of dynamic arrays, whose empty positions are initially initialised with 0 (or #0, or nil, or ...).
Jonas 11:37, 2 June 2014 (CEST)
Thank you for your comment! I think, its maybe a bug, cause if the type "OldString" is declared in the procedure, the statement is false, otherwise seems to vote. I asked in the forum.
--Michl 13:46, 2 June 2014 (CEST)
All global variables are always initialised with 0/#0/nil/... That is documented in the manual, has nothing to do with array of char, and should therefore not be mentioned here because it is orthogonal.
Jonas 14:43, 2 June 2014 (CEST)