[fpc-devel]Re: array of char

R Wong an0nym0usann0yance at hotmail.com
Fri Sep 29 07:32:09 CEST 2000


> const
>  CharsDes1:array[0..383]of char=
>   '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'+
>  (snipped 4 identical lines...)
>   '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
>
> var rr,rt:longint;
>
> begin   for rr:=0 to 383 do write(CharsDes1[rr]);     end.
>
> The program just writes the first 255 characters and
> the other characters instead of write zero codes.
>
> I think it's a bug because the 'string' isn't equal 'array[0..x]of char'.

The problem is that, when you Assign something to a var-constant
(initialized variable array),
the expression (your long string) will get processed first, before passing
along to the const/var.
Thus, the shortstring Concatenation operation truncated your string before
it is passed to the const.

It is perfectly fine with your data structure. The problem is the way that
it is assigned.
(In other words, you cannot initialize that array directly)

This problem dates back to a similar TP7 problem, where
const BigNum=1000000000000000;
will cause an error, because TP7 assumes any number without decimal to be an
integer.
(This does not happen on FPC, because it is clever enough to do implicit
typecast on constants as well)

Any solutions (tricks, hacks, ...) ?




More information about the fpc-devel mailing list