[fpc-pascal]typed constants
Vinzent Hoefler
JeLlyFish.software at gmx.net
Thu Jan 2 19:23:20 CET 2003
On Thursday 02 January 2003 09:31, Michael.VanCanneyt at Wisa.be wrote:
> On Thu, 2 Jan 2003, Vinzent Hoefler wrote:
> > On Thursday 02 January 2003 08:43, Peter Vreman wrote:
>
> > > 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);
Oh, this one. To assign specific values to an enum position. Well, this
can be considered as a constant value, so the "=" would be quite ok for
me.
> In Free pascal, it was:
>
> Type
> TEnum = (enOne,entwo,enThree:=4);
>
> Its main purpose is to support translation of C enums
The intention is clear (in C, enums are just named integer constants
anyway).
[I just wouldn't like to have declaration and implementation at the same
place. The Ada approach with its representation clauses looks more
appealing to me.]
> > > > 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.
[I think this one is clarified now, thanks]
> program tini;
>
> Const
> A = 1;
> B = 2;
>
> Procedure ProcA;
>
> Var
> C : Integer = A+B;
> D : Boolean = (A=B);
To get back to the point, I understood that this will "probably be
implemented as initialized variables."
[see <Pine.LNX.4.44.0301021020000.871-100000 at home.wisa.be>]
Rereading that message again seems to reveal to me, that this means
_both_ syntactic forms will be implemented as initalized variables?
*dizzled*
I thought, the only difference between local typed constants and
initialized variables will be that
(a) the "const" declaration implements them as global with just local
scope and
(b) "var" would initialize it each time the subprogram is called?
And especially in case of (b), why should it not be allowed to use
variable parameters as initialization value?
Anyway, I would think that an assignment operator ":=" is more
appropriate for a variable assignment in those cases. It would also
help to distinguish between both cases then, because people tend to
write declarations in single const/var blocks, so you cannot tell from
the first look, if this one is a local typed constant or an initialized
variable. With the distinction between "=" and ":=" you could do that.
> With correct output :
> home: >ppc386-1.1 tini.pp
> home: >tini
> 3
> FALSE
I did not expect otherwise. :-)
Vinzent.
--
There are three kinds of lies: Lies, Damn Lies, and Statistics.
-- Disraeli
More information about the fpc-pascal
mailing list