🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.borland
Article #186

Re: CASE in records

#186
From: The Scarlet Manuka
Date: Wed, 31 May 2000 00:00
28 lines
2354 bytes
byatesiii@my-deja.com wrote:
[variant records]
> Your 2nd example allows a person to store either two words or four
> bytes (same size) within the record, and Pascal chooses which one by
> the type of the data you are storing there (byte or word).
> In some implementations I think the size of each variant had to be the
> same, or the larger ones came first. Your first example doesn't appear
> to follow this restriction. But then again, I'm a UCSD Pascal
> programmer... the only one left, I imagine :)

Variant records can have variants of different sizes; enough space is
allocated to store the largest. The type used is determined when the data is
read or written; this makes it easy to convert data between compatible 
types.  For instance, TP has a variant record type for the registers; so you
can store data in the 8-bit registers and read it from the 16-bit registers,
or the other way around. Many other applications are possible. In
particular, it makes it possible to pass different but related types to a
single procedure or function, as in your polygon example. Each form needs
its own parameters and storage, but a single routine can handle them by
using the variant record.

-- 
______________________________________________________________________
     The Scarlet Manuka,      |        Nitpickers' Party motto:
  Pratchett Quoter At Large,  |  "He who guards his lips guards his
 First Prophet of Bonni, is:  |  soul, but he who speaks rashly will
   sacha@maths.uwa.edu.au     |    come to ruin." -- Proverbs 13:3
______________________________|_______________________________________
Technical Details
Message-ID: <8h24cp$gt3$1@enyo.uwa.edu.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3933FF8D.FFBE7575@vgrieken.demon.nl> <8h10un$lln$1@nnrp1.deja.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111659,60a819bd5bee7e02
X-Google-Attributes: gid111659,public
X-Google-Thread: 108ebd,60a819bd5bee7e02
X-Google-Attributes: gid108ebd,public
From: sacha@maths.uwa.edu.au (The Scarlet Manuka)
Subject: Re: CASE in records
Date: 2000/05/31
Message-ID: <8h24cp$gt3$1@enyo.uwa.edu.au>
X-Deja-AN: 629309984
References: <3933FF8D.FFBE7575@vgrieken.demon.nl> <8h10un$lln$1@nnrp1.deja.com>
X-Trace: enyo.uwa.edu.au 959747289 17315 130.95.16.65 (31 May 2000 04:28:09 GMT)
Organization: *wibble*
User-Agent: tin/pre-1.4-971106 (UNIX) (IRIX/6.5 (IP22))
Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal
X-Complaints-To: usenet@news.uwa.edu.au