[fpc-pascal] type definitions etc

Hans Maartensson cirkulation at maartensson.net
Thu May 26 22:59:09 CEST 2005

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

>The standard solution is to
>define the pointer type first:
>|   ptr_sometype = ^sometype;
>|   some_type =
>|   record
>|      p : ptr_sometype;
>|      ...
>|   end;

OK, I didn't try that, so it is allowed to define a type as a pointer to a 
type that is defined later.

> > Also the following call to a win32 API function is not allowed any
> > more:
> >
> > invalidaterect(windows, 0, true);
>Have you actually tried "InvalidateRect (windows, NIL, True);"?

I have overlooked that, you are right, it works, due to function 
overloading, as you explain. So in the old version it was 0, now it is nil, OK.

> > Finally I would like to ask about the following.
> > The compiler does not allow a procedure definition like:
> >
> > procedure someproc(p: ^double);
> >
> > whereas the following is perfectly possible:
> >
> > type Tpdouble = ^double;
> > procedure f(p: Tpdouble);
> >
> > Is there a good reason for this? Why isn't  ^double a valid type
> > everywhere?
>type1 = ^double;
>type2 = ^double;
>should be considered different types. So if you define the type in the
>procedure declaration, you couldn't call it, just because you can't
>declare a variable of the same type for the argument. The only allowed
>argument would be NIL, which I think is a little bit pointless.

OK that makes sense.

>BTW, why don't you use "procedure f(const/var/out p : double);" instead
>to get rid of as much pointers as possible and use the right parameter
>modes which also have the side effect of being more self documenting?

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.

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.

Thank you very much for the help.

Hans Maartensson

More information about the fpc-pascal mailing list