13.07.2015 Views

apple-pascal-1.3-manual

apple-pascal-1.3-manual

apple-pascal-1.3-manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Thus our program could, for example, store a character as MAGIC.SYMBOLand retrieve its bit pattern as the integer MAGIC.NUMBER. It could store orretrieve either as an array of bits (each represented by its boolean value). Atypical statement to write out the binary value of the data stored in MAGICmight look like this:FOR H := 15 DOWHTO 0 DOIF MAGIC.BIHARYCHJ THEHWRITE C'1'>ELSE WRITE C'B'>;The rules for forming and using free union variant records are the same asfor ordinary variant records, except that the tag field identifier is omitted. Inparticular, free union variant fields do not need to be all the same size. Inthe foregoing example, if we had declared MAGIC.BINARY as anARRA Y[0 .. 7] OF BOOLEAN it would have accessed only the first byte of thetwo-byte memory space reserved for the whole record variable.Using free union variant records is one of several ways to defeat the "strongtyping" characteristic of Pascal. Others are listed in Chapter 16. The waysthat various data types are stored in memory are described in Appendix 3C.Packed RecordsWhen records are declared normally, Pascal allocates a minimum of oneword (two bytes, or 16 bits) of memory for each field. When one or morefields are of types that can be stored in less than a whole word, you canconserve memory space by declaring the record as packed. To do this,simply write the word PACKED just before the word RECORD.Here is an example of a packed record declaration:TYPE MICRO = PACKED RECORDF1, F2, F3 : 0 .. 31;LASTBIT : BOOLEAHEHD;The three integer subrange fields Fl, F2, and F3 each need five bits ofmemory; LASTBIT needs one. Because MICRO is declared as packed,variables of its type take up only one 16-bit word of memory. If the wordPACKED were omitted, variables of type MICRO would occupy four words,one for each field.III-56Chapter 4: Structured Data Types

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!