GNU Pascal Homepage - gpc - gpc-announce - gpc-de - gpc-doc
Diese Seite auf deutsch

Mail #13509

Back to main page of archive

Previous mail   Next mail   Unformatted/full headers
Overview  10 days   Subject   Date   Thread   Author  

From: Waldek Hebisch
Subject: (gpc-20060215) fillchar bug
Date: 2 Apr 2006, 20:48:40

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.
> 
> Reading specs from /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.6/specs
> Configured with: ../gcc-3.4.6/configure --enable-languages=c,c++,pascal
>   --enable-shared --enable-threads-posix --enable-__cxa_atexit
> Thread model: posix
> gpc version 20060215, based on gcc-3.4.6
> 
>    Russ

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, ' ');

and I will work. However, I think that the correct way is:

  setlength(s, s.capacity);
  fillchar(s[1..length(s)], length(s), ' ');

Alternatively, you char turn range checking off. 

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.

Previous mail   Next mail   Unformatted/full headers
Overview  10 days   Subject   Date   Thread   Author  


Replies

Author Subject Date
Russell Whitaker (gpc-20060215) fillchar bug 2 Apr 2006, 12:36:14
Frank Heckenbach (gpc-20060215) fillchar bug 2 Apr 2006, 22:49:55
Frank Heckenbach (gpc-20060215) fillchar bug 2 Apr 2006, 22:51:21

In reply to

Author Subject Date
Russell Whitaker (gpc-20060215) fillchar bug 2 Apr 2006, 09:30:43

Back to main page of archive


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).