FYI:

I thought a little bit more about your answer and decided to try it with my Stanford compiler; in fact, your pointer parameter is a VALUE parameter, and because it is copied into the procedure's local stack, it should be treated much like a local variable IMO, and there it is indeed possible to use the  ^basetype notation and all the other type notations, too. Therefore IMO it should also be possible to define new types with value parameters, be it useful or not. The normal Pascal assignment rules apply (parameter passing to value parameters is much like normal assignment, with some
tolerance regarding types).

So I decided to allow it, but for value parameters only. For var and const parameter, different rules apply, because there we have conformant strings for example (strings without length) etc.; so I call a different parsing function, when I have a var or const keyword. Without var or const, I call the same parsing function for types which I call in var declarations etc, too.

So now the following program compiles (and runs) without problem:

program TESTPTR ( OUTPUT ) ;

//**********************************************************************
//$A+
//**********************************************************************

type CFORW = record
               SOMEV : INTEGER ;
               C : -> CHAIN ;
             end ;
     CHAIN = record
               N : INTEGER ;
               NEXT : -> CHAIN ;
             end ;

var K : -> CHAIN ;
    X : CFORW ;

procedure PRINT ( X : -> CHAIN ) ;

   begin (* PRINT *)
     while X <> NIL do
       begin
         WRITELN ( X -> . N ) ;
         X := X -> . NEXT
       end (* while *)
   end (* PRINT *) ;

begin (* HAUPTPROGRAMM *)
  NEW ( K ) ;
  X . C := K ;
  K -> . N := 1 ;
  NEW ( K -> . NEXT ) ;
  K := K -> . NEXT ;
  K -> . N := 2 ;
  NEW ( K -> . NEXT ) ;
  K := K -> . NEXT ;
  K -> . N := 3 ;
  K -> . NEXT := NIL ;
  PRINT ( X . C ) ;
end (* HAUPTPROGRAMM *) .


- I use a different notation for the pointer symbol; ^ is possible, too

- there is no declaration for the -> CHAIN pointer type, nowhere

- it is even possible to use it in the CFORW record, prior to the definition of CHAIN
(those forward references are checked later)

Kind regards

Bernd


Am 10.06.2019 um 03:26 schrieb Ben Grasset:

On Sun, Jun 9, 2019 at 8:37 PM Bernd Oppolzer <bernd.oppol...@t-online.de <mailto:bernd.oppol...@t-online.de>> wrote:

    I am still not sure, if it is a good idea, because this would be
    an exception for pointer types;
    other type constructors like arrays, records, enumerations etc.
    are still not supported ...
    and it does not make sense IMO to support them.


 People keep saying this as though the *entire concept *of adding even the smallest new thing syntactically to FPC is a completely new idea (which it obviously is not.) Adding this would *not *be any kind of notable "exception" in any practical sense, unless you're holding FPC to a purely fictional standard for Pascal
that it does not actually currently follow in reality.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to