Initializers on const and var

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Initializers on const and var

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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Initializers on const and var

Michael Van Canneyt


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.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Initializers on const and var

Marc Santhoff
Am Dienstag, den 03.06.2008, 15:41 +0200 schrieb Michael Van Canneyt:

>
> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal