Initializing variant records - how?

CBFalconer cbfalconer at yahoo.com
Tue Dec 4 22:28:33 CET 2001


Martin G C Davies wrote:
> 
> > -----Original Message-----
> > From: gpc-owner at gnu.de [mailto:gpc-owner at gnu.de]On Behalf Of CBFalconer
> > Sent: 04 December 2001 15:12

... snip ...

> > What is wrong with the purely standard construct of:
> >
> > program varaint_test( input , output ) ;
> >
> > type
> >     short          = -32768..32767;
> >     variant_record = record
> >         case boolean of
> > false : (   compare    : integer ) ;
> > true  : (   case boolean of
> >     false : ( page ,
> >               offset       : short ) ;
> >     true  : ( len ,
> >               disp         : short ) ) ;
> >         end ;
> >
> > var
> >     mgcd : variant_record;
> >
> > PROCEDURE initvr(VAR r : variant_record);
> >     BEGIN
> >     r.compare := 12345;
> >     END;
> >
> > begin
> >     initvr(mgcd);
> >     writeln( 'ok' ) ;
> > end.
> 
> Of course, I just sent a small example program to demo what I want to do.
> What I have is a program that currently runs using the Pascal compilers
> mentioned above. We'd like it to run under GPC so I am trying to port it.
> Currently I have HUGE tables that are all compile time initialized. For sure
> I could rewrite the initialization to be run-time - I'm just trying to find
> out if GPC can actually do what I want. Having said that, thanks for the
> suggestion - it's certainly the best (only) suggestion so far.

In my opinion sticking with standard methods such as this is much
easier on the eventual system.  You can have variations on the
initializing code, so you can use it or a variation on various
instances of the data.  In addition, the initialization code is
firmly separated, and thus is not in the working set (after use)
on modern systems.  This is more efficient use of memory, and
speeds up the rest of your code because of better locality.

You can also have high speed initializations of the form
(standard)

   vr2 := vr1;

Note that you can always enforce equality, while you cannot check
it.

Your so-called compile time initialization probably isn't, if you
are declaring instances of the record locally.  So the run time
code is already there.  So for local instances you may want to
have:

  VAR (* global *)
     initvar   : myvarcd;

...
  PROCEDURE initvr(VAR r : myvarcd); BEGIN (* whatever *) END;
...
  PROCEDURE anythingatanynestlevel;

    VAR
       vr    : myvarcd;

    BEGIN
    vr := initvar;
    ...
    END;
...
  BEGIN (* prog *)
  initvr(initvar);
  ...
  END.

and you have the triple advantages of speed, efficiency, and full
portability.

You may notice that I don't believe Pascal needs many extensions
:-)

-- 
Chuck F (cbfalconer at yahoo.com) (cbfalconer at XXXXworldnet.att.net)
   Available for consulting/temporary embedded and systems.
   (Remove "XXXX" from reply address. yahoo works unmodified)
   mailto:uce at ftc.gov  (for spambots to harvest)




More information about the Gpc mailing list