Hi,
I need (want!) to initialize variant records. I have created a small example - doesn't compile of course because I can't find how to do it. I guess GPC can do it since VS_Pascal (IBM/MVS), VAXPascal and SPARCPascal all allow me to do it (all in different ways of course!).
Anyone?
Cheers, Martin.
program varaint_test( input , output ) ;
type variant_record = record case boolean of false : ( compare : integer( 32 ) ) ; true : (
case boolean of false : ( page , offset : integer( 16 ) ) ; true : ( len , disp : integer( 16 ) ) ; ) ; end ;
var mgcd : variant_record := ( compare : 12345 ) ; (* How can I do this? *)
begin writeln( 'ok' ) ; end.
Martin G C Davies wrote:
I need (want!) to initialize variant records. I have created a small example - doesn't compile of course because I can't find how to do it. I guess GPC can do it since VS_Pascal (IBM/MVS), VAXPascal and SPARCPascal all allow me to do it (all in different ways of course!).
Anyone?
Cheers, Martin.
program varaint_test( input , output ) ;
type variant_record = record case boolean of false : ( compare : integer( 32 ) ) ; true : (
case boolean of false : ( page , offset : integer( 16 ) ) ; true : ( len , disp : integer( 16 ) ) ; ) ; end ;
var mgcd : variant_record := ( compare : 12345 ) ; (* How can I do this? *)
begin writeln( 'ok' ) ; end.
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.
-----Original Message----- From: gpc-owner@gnu.de [mailto:gpc-owner@gnu.de]On Behalf Of CBFalconer Sent: 04 December 2001 15:12 To: gpc@gnu.de Subject: Re: Initializing variant records - how?
Martin G C Davies wrote:
I need (want!) to initialize variant records. I have created a small example - doesn't compile of course because I can't find how to do it. I guess GPC can do it since VS_Pascal (IBM/MVS), VAXPascal and
SPARCPascal all
allow me to do it (all in different ways of course!).
Anyone?
Cheers, Martin.
program varaint_test( input , output ) ;
type variant_record = record case boolean of false : ( compare : integer( 32 ) ) ; true : (
case boolean of false : ( page , offset : integer( 16 ) ) ; true : ( len , disp : integer( 16 ) ) ; ) ; end ;
var mgcd : variant_record := ( compare : 12345 ) ; (* How can I
do this? *)
begin writeln( 'ok' ) ; end.
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.
Cheers, Martin.
Martin G C Davies wrote:
-----Original Message----- From: gpc-owner@gnu.de [mailto:gpc-owner@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 :-)
-----Original Message----- From: gpc-owner@gnu.de [mailto:gpc-owner@gnu.de]On Behalf Of CBFalconer Sent: 04 December 2001 21:29 To: gpc@gnu.de Subject: Re: Initializing variant records - how?
<snip>
You may notice that I don't believe Pascal needs many extensions :-)
Fair enough - but we're slightly moving off the original question. What I have is 240,000 lines of code in 159 compilation units. The program is largely a table driven one and a number of modules are basically just the definition and compile-time (honestly!) initialization. Some records have variants.
So the original question was:- Can I get GPC to initialize variant records? If the answer is "No" I understand how to get around the problem - I'd just prefer not to if I don't have to.
Cheers, Martin.
Martin G C Davies wrote:
Fair enough - but we're slightly moving off the original question. What I have is 240,000 lines of code in 159 compilation units. The program is largely a table driven one and a number of modules are basically just the definition and compile-time (honestly!) initialization. Some records have variants.
So the original question was:- Can I get GPC to initialize variant records? If the answer is "No" I understand how to get around the problem - I'd just prefer not to if I don't have to.
I'm afraid the answer is no (I'll add am error message to make this clear). Adding support for this seems to require some work (i.e., it's not just a bug, it's a whole missing feature).
Depending on the situation it might be an acceptable work-around to avoid the variants for now (i.e., make it one big record).
Frank
CBFalconer wrote:
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.
Oh, that depends. Most systems use page sizes of 4 KB and bigger, so unless the initialization code fills one or several such pages, it can be paged out later. If it's small, it may well lay within the same page(s) as routines use later, and thus stay in the working set.
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.
In this case, yes. (But for his huge tables, I suppose they're declared gobally.)
You may notice that I don't believe Pascal needs many extensions :-)
You know that I disagree, but since initializations are standard, anyway, that's not really the point here. (Though GPC currently supports only (non-standard) BP style initialization, and EP initialization only in simple cases.)
Frank