On 16 Mar 2001, at 13:00, Eike Lange wrote:
Hi! With the following program, I get the error storage size of 'Bar' isn't constant Whats wrong? Is there another way to tell the compiler the storage size of a const value?
program test; const Foo : integer = 4; var Bar:array[1..foo] of integer; begin end.
What you have done is to "misuse" an initialized variable as a constant (I think that BP calls them "typed constants"). While that may be accepted (with a warning under GPC) for some uses, it cannot be used as a constant value in declaring data types. Why? Because, as a typed constant, its value can be changed - then what happens to your array? The compiler needs a value that is truly constant (i.e., that cannot be changed) for these purposes.
This is what you want;
program test; const Foo = 4; var Bar:array[1..foo] of integer; begin end.
Best regards, The Chief --------- Prof. Abimbola Olowofoyeku (The African Chief) Author of Chief's Installer Pro v5.24 for Win32 Email: African_Chief@bigfoot.com http://www.bigfoot.com/~african_chief/
Prof. A Olowofoyeku (The African Chief) wrote:
On 16 Mar 2001, at 13:00, Eike Lange wrote:
Hi! With the following program, I get the error storage size of 'Bar' isn't constant Whats wrong? Is there another way to tell the compiler the storage size of a const value?
program test; const Foo : integer = 4; var Bar:array[1..foo] of integer; begin end.
What you have done is to "misuse" an initialized variable as a constant (I think that BP calls them "typed constants"). While that may be accepted (with a warning under GPC) for some uses, it cannot be used as a constant value in declaring data types. Why? Because, as a typed constant, its value can be changed - then what happens to your array? The compiler needs a value that is truly constant (i.e., that cannot be changed) for these purposes.
This is what you want;
program test; const Foo = 4; var Bar:array[1..foo] of integer; begin end.
If for some reason you want to stick a type to the constant, you could do BP-style type casting (`const Foo = Integer (4);'), though it's hard to imagine what this could be useful for (especially with `Integer' which is the default type for constants that fit in its range, there may be a point in strange situations to make a constant of a different integer or real type)...
Frank