Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
From: Russell Whitaker
Subject: (gpc-20060215) fillchar bug
Date: 2 Apr 2006, 12:36:14
On Sun, 2 Apr 2006, Waldek Hebisch wrote:
> Russell Whitaker wrote:
>> hi
>>
>> The following compiles but no longer works:
>>
>> program fill;
>> var
>> s: string(10);
>> begin
>> fillchar(s[1], s.capacity, ' ');
>> writeln("ok");
>> end.
>>
>
> Do you get a message about out of range value? If yes then strictly
> speaking the compiler is right: s is uninitialized, so its length
> is set to 0, hence access to s[1] is illegal (out of range). In fact,
> I see another problem with the code above: s[1] is a single char,
> but fillchar acceses also s[2],... which strictly speaking is another
> out of bound access (but ATM compiler can not detect this problem).
>
> I would say that fillchar is incompatible with range checking (at least
> now). ATM you can say:
>
> setlength(s, 10);
> fillchar(s[1], s.capacity, ' ');
Thanks. Adding setlength did the job.
> and I will work. However, I think that the correct way is:
>
> setlength(s, s.capacity);
> fillchar(s[1..length(s)], length(s), ' ');
shouldn't that be
fillchar(s[1], length(s), ' '); ?
> In the future we may teach the compiler that fillchar is special, so
> it applies to it relaxed range checking rules, but that would
> require non-trivial changes in the compiler.
>
perhaps something like:
if ( start+count ) GT s.capacity then out-of-range-error
if ( start+count ) GT length(s) then setlength( s, start+count)
Also, if the fillchar line is written as
fillchar( s, count, Afillchar );
it should default to
fillchar( s[1], count, Afillchar );
current behavior fillchar( s, ... overwrites length (and capacity?)
fields.
Russ
Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
| Author | Subject | Date |
|---|---|---|
| Frank Heckenbach | (gpc-20060215) fillchar bug | 2 Apr 2006, 22:49:55 |
| Author | Subject | Date |
|---|---|---|
| Waldek Hebisch | (gpc-20060215) fillchar bug | 2 Apr 2006, 20:48:40 |
Note: This page contains information that does not originate from the owner of this web site, but from the authors of the mails archived. The owner of this web site is not responsible for the content of such information. Any use of that infomation requires the consent of the respective author.
Where WWW addresses (URLs) in the mails archived are marked as hyperlinks, this is only for the comfort of the reader. The content of the web pages linked to like this does not necessarily reflect the opinion of the owner of this web site or of the authors of the mails archived. The owner of this web site is not responsible for the content of such web pages. Those pages are explicitly not to be considered as part of the content of this page, but merely as references.
This page was created by Crystal 0.999 (Linux 2.4.27/i686).