[fpc-pascal] type definitions etc
Vinzent Hoefler
JeLlyFish.software at gmx.net
Fri May 27 12:37:28 CEST 2005
On Thursday 26 May 2005 20:59, Hans Maartensson wrote:
> At 14:50 26-05-2005, you wrote:
> > > .....
> > > type sometype = record
> > > n: longint;
> > > p: ^sometype
> > > end;
> >
> >This was never allowed in Pascal, AFAIK.
>
> FPC version 1.0.12 compiled it OK
Then it looks more like a bug.
> OK, I didn't try that, so it is allowed to define a type as a pointer
> to a type that is defined later.
Yes, but _only_ if the type declaration comes _immediately_ after the
pointer type declaration. So you can't just declare a bunch of pointer
types and defer the actual type-declaration to a later point, that
won't work.
> I do avoid pointers when I can, but sometimes it is not known, how
> many variables are needed before the program is running. So you let
> the program allocate some memory, put the values in there, and then
> you need pointers to keep track of then.
Yes. But even then you can dereference your pointers early and not carry
them through the whole program.
I mean, a "procedure Foo (var V : Double);" can still be called with a
pointer variable like "Foo (pd^)" and then used as normal variable in
subsequent routines. This can even eliminate lots of (unnecessary) NIL
checks. (I recently converted a lot of pointer stuff that way, the
original was more or less a one-to-one translation from C-code, so you
can perhaps imagine...).
> On the other hand, I just read in the documentation that the new
> version of FPC (I used v.1.0.12 before) has something called dynamic
> array. Those arrays will fix that kind of problem, I really like that
> new feature.
That might be another option. I haven't tried it yet, so I can't say
anything about it, but if it works properly, it looks even better.
Vinzent.
More information about the fpc-pascal
mailing list