Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-01

Re: Initializers on const and var

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff
to Michael Van Canneyt: This is the error; The values must be known at compile time. Michael.
Michael Van Canneyt wrote 21 lines
On Tue, 3 Jun 2008, Marc Santhoff wrote: > Hi, > > is it possible to have an array initialized with variables? > > I tried sth. like this (by accident, not intentionally): > > const > ctypes: array [0..9] of hid_t = > ( > H5T_NATIVE_INT, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_C_S1, > H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_NATIVE_HBOOL, H5T_NATIVE_HBOOL > ); > > assuming the names in upper case are constants. But in fact they are > variables (declared "cvar; external" but I think that's not the cause of > the error). This is the error; The values must be known at compile time.
Okay, but that hold true for any kind of variable, not only those "cvar;
external;" ones.

Anyway, I'll see if changing the base type of the array to pointers is possible.

Thanks,
Marc

Reply by email

Marc Santhoff

Hi,

is it possible to have an array initialized with variables?

I tried sth. like this (by accident, not intentionally):

const
ctypes: array [0..9] of hid_t =
(
H5T_NATIVE_INT, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_NATIVE_HBOOL, H5T_NATIVE_HBOOL

	);

assuming the names in upper case are constants. But in fact they are variables (declared "cvar; external" but I think that's not the cause of the error).

var
	H5T_NATIVE_INT: hid_t;
	...
	H5T_NATIVE_INT_g : hid_t;cvar;external;
initialization
	H5T_NATIVE_INT := H5T_NATIVE_INT_g;

The compiler does find an "illegal expression" after the first item in the initializer.

Is there another way but moving the initialization from the interface to the implementation of some "procedure init"? I'd like to see the declaration in the interface part.

TIA,
Marc

Reply by email

Michael Van Canneyt
to Marc Santhoff
Marc Santhoff wrote 16 lines
Hi, is it possible to have an array initialized with variables? I tried sth. like this (by accident, not intentionally): const ctypes: array [0..9] of hid_t = ( H5T_NATIVE_INT, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_C_S1, H5T_NATIVE_HBOOL, H5T_NATIVE_HBOOL ); assuming the names in upper case are constants. But in fact they are variables (declared "cvar; external" but I think that's not the cause of the error).

This is the error; The values must be known at compile time.

Michael.

Reply by email