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.