For what it's worth, one of the most important features for me, of Pascal over C, is that Pascal strings can store ANY character, including NUL. I would guess than in at least half the programs I have written over the years that use strings, I have required this capability! This is also why I will never use Component Pascal - Uncle Wirth made a serious mistake by selecting C-style strings for that language!
Regards, Joe.
-----Original Message----- From: Frank Heckenbach [SMTP:frank@g-n-u.de] Sent: Thursday, 31 May 2001 7:23 To: gpc@gnu.de; adam.oldham@marconi.com Subject: Re: Null Character
Oldham, Adam wrote:
What is the Null Character to GPC for use in CHARs and STRINGs? In my previopus compiler \00 was used for this.
I think we have discussed this several times already. (You are subscribed to this list and got the replies, didn't you?)
Again, if another compiler treats '\00' as a NUL character, that's simply wrong, because in Pascal a string enclosed in '' must treat every character literally (except ' itself which must be doubled to get a literal ').
VAR a : array [1..4] of chars; b : array [1..4] of chars; c : array [1..4] of chars; d : array [1..4] of chars;
BEGIN
a = '\00\00\00\00';
That's a 12 char string.
FILLCHAR(b, 4, CHR(0));
That's correct.
c ='0000';
That's 4 times the ASCII '0' (#48).
d = '';
That's an empty string which, if assigned to a fixed char array, gets filled with spaces (according to the standard). Since Pascal strings are not zero-terminated (as C strings are), no NUL appears here.
You can do it without FillChar as well: Chr (0) + Chr (0) + Chr (0) + Chr (0)
Or (non-standard Borland-compatible way): #0#0#0#0
Or (non-standard GPC extension): "\0\0\0\0" (note the double quotes!)
Also, with GPC, when a new variable is defined, is it automatically zeroed out?
No (even if they sometimes happen to be zeroed, you can't rely on this).
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/ GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html