Russell Whitaker wrote:
Some time age wrote a program using an array of pointers to fixed capacity strings. The plan is to rewrite the program to use variable capacity strings. So while playing to see what *might* work
got this:
../../../gcc-2.95.3/gcc/p/types.c:1107: failed assertion `capacity && TREE_CODE (capacity) == INTEGER_CST' buff.pas:25: Internal compiler error in `declared_string_capacity', at types.c:1107 Please submit a full bug report to the GPC mailing list gpc@gnu.de. See URL:http://home.pages.de/~GNU-Pascal/todo.html for details.
from this:
unit Buff; interface
const MAXLINES = 20000;
type lline = string ( 4000 ); {buffer for data xfer}
procedure BB_AppendLine( Aline: lline ); {adds to end}
implementation var cap : integer;
type ptrline = ^Line; Line = string ( cap ); TbbArray = array[1..MAXLINES] of ptrline;
var BigBuffer : Tbbarray; {array of pointers to data} LineCount : integer = 0; FileUpdate : boolean = false; LineItem : Line;
This won't work. The size of LineItem (a global variable) depends on the value of cap (another variable).
Within a local routine, this might work, but still produce nonsense since cap is not initialized.
procedure BB_AddLine( Aline: lline ); begin cap := lline.length;
lline is a type, so this can't work, either (what's the length of a type?). If you want to get the capacity, you can use `High (lline)'. Or did you mean `Length (ALine)'?
BigBuffer[ LineCount ] := new( ptrline, LineItem );
The 2nd parameter is (this way of using) `New' is the capacity (Integer), but LineItem is a string value. Furthermore, since ptrline is already a pointer to a discriminated string, the 2nd parameter is spurious, anyway. (Better, e.g., `New (PString, cap)' where PString is declared as `^String').
BigBuffer[ LineCount ]^ := Aline; inc( LineCount );
An unrelated error: LineCount starts at 0, but the index of BigBuffer at one. You probably meant to increment LineCount before the assignments.
Incidently, this won't work, either:
type cap = integer; Aline = string( cap ); {gives err msg}
How should this work? cap is a type, but the actual capacity must be a number.
I've fixed a few details so there will now be a better error message instead of the internal compiler error (russ3[ab].pas), but in general, type declarations that depend on variables look strange to me -- I'd have to check if they're allowed in the standard, and if so, we might have to fix some things in GPC, but IMHO it's easier to write and read (and compile ;-) to declare such types as pointers to undiscriminated strings and give the capacity as the parameter to `New'.
Frank