[fpc-pascal]typed constants

Michael.VanCanneyt at Wisa.be Michael.VanCanneyt at Wisa.be
Thu Jan 2 15:31:20 CET 2003


On Thu, 2 Jan 2003, Vinzent Hoefler wrote:

> On Thursday 02 January 2003 08:43, Peter Vreman wrote:
> > > On Thursday 02 January 2003 04:28, Michael.VanCanneyt at Wisa.be wrote:
> >
> > >> Procedure doit (N : Integer);
> > >>
> > >> Const
> > >>   C : Integer = 1;
> > >>
> > >> Var
> > >>   A : Integer = 0;
> > >
> > > Is this a typo? This should be
> > >
> > > |A : Integer := 0;
> > >
> > > shouldn't it? I mean it is a variable, so you can only *assign* an
> > > initial value to it instead of setting it equal to some value.
> >
> > Go and tell Borland about it, they use '=' for assigning enums. FPC
> > already supported that with ':='.
>
> *eeek* In Delphi you can write the following?
>
> |var
> |  X : some_enum = enum_value;
>
> I thought, this kind of syntax is only allowed for typed "constants"?

No:

Type
  TEnum = (enOne,entwo,enThree=4);

In Free pascal, it was:

Type
  TEnum = (enOne,entwo,enThree:=4);

Its main purpose is to support translation of C enums

>
> <cite>
> |> I recommend to the compiler guys (when schedule permits) implementing
> |> the compiler initilization of local variables (which have an
> |> initialization value declared)...that is, it gets initialized when it
> |> gets pushed onto the stack.
> |
> |The matter is being discussed by the core members.
> |The response I've had till now indicate that probably we'll implement
> |it as initialized variables.
> </cite>
>
> So I did not understand the last sentence correctly?
>
> > It's all about compatibility. When we are not compatible with Delphi
> > we get a lot of bug reports.
>
> Even if it is right..., yes I know. So "initialized variables" are
> already supported in Delphi and you simply have to be compatible?
>
> > > with the "=" operator. Consider this:
> > > |Var
> > > |  A : boolean = C = D;
> > >
> > > Looks a little bit crazy to me.
> >
> > That is also not allowed. You need to specify a constant value.
>
> Well, at least with
>
> |const
> |  C = 5;
> |  D = 6;
>
> the line above should legally evaluate to False as initial value for A.
> However, I even see no reason why
>
> |procedure Do_It (C, D : Integer);
> |var
> |  A : boolean := C = D;
>
> shouldn't be allowed for initialization.

Peter was wrong, it is allowed (note the use of '=', not ':='):

program  tini;

Const
  A = 1;
  B = 2;

Procedure ProcA;

Var
  C : Integer = A+B;
  D : Boolean = (A=B);

begin
  Writeln(c);
  Writeln(d);
end;

begin
  Proca;
end.

With correct output :
home: >ppc386-1.1 tini.pp
home: >tini
3
FALSE

Michael.





More information about the fpc-pascal mailing list