PZ04B - Arrays

PZ04B - Arrays

PZ04B - Arrays and records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 6.1 PZ04B Programming Language design and Implementation -4th Edition CopyrightPrentice Hall, 2000 1 Array accessing An array is an ordered sequence of identical objects. The ordering is determined by a scalar data object (usually integer or enumeration data). This value is called the subscript or index, and written as A[I] for array A and subscript I.

Multidimensional arrays have more than one subscript. A 2-dimensional array can be modeled as the boxes on a rectangular grid. The L-value for array element A[I,J]is given by an accessing formula dependent upon orientation... PZ04B Programming Language design and Implementation -4th Edition CopyrightPrentice Hall, 2000 2 Slices PZ04B Programming Language design and Implementation -4th Edition

CopyrightPrentice Hall, 2000 3 Structs in C Representation: a sequence of objects: record { A: object; B: object; C: object } PZ04B Programming Language design and Implementation -4th Edition CopyrightPrentice Hall, 2000 8

Union types typedef union { int X; float Y; char Z[4];} B; B P; Similar to records, except all have overlapping (same) L-value. But problems can occur. What happens below? P.X = 142; printf(%O\n, P.Z[3]) All 3 data objects have same L-value and occupy same storage. No enforcement of type checking. Poor language design PZ04B Programming Language design and Implementation -4th Edition CopyrightPrentice Hall, 2000

9 Variant records type PayType=(Salaried, Hourly); var Employee:record ID: integer; Dept: array[1..3] of char; Age: integer; case PayClass: PayType of Salaried:(MonthlyRate:real; StartDate:integer); Hourly:(HourRate:real; Reg:integer; Overtime:integer) end PZ04B

Programming Language design and Implementation -4th Edition CopyrightPrentice Hall, 2000 10 Variant records (continued) Tagged type type case union type - Pascal variant records whichtype = (inttype, realtype, chartype); uniontype = record V: whichtype of inttype: (X: integer); realtype: (Y: real);

chartype: (Z: char4); Assumes string of length 4 end But can still subvert tagging: var P: uniontype P.V = inttype; P.X = 142; P.V = chartype; What is P.V value now? PZ04B Programming Language design and Implementation -4th Edition CopyrightPrentice Hall, 2000 11

Recently Viewed Presentations

  • THE CARBON CYCLE TEK: Diagram abiotic cycles, including

    THE CARBON CYCLE TEK: Diagram abiotic cycles, including

    THE CARBON CYCLE. TEK: Diagram abiotic cycles, including the carbon, nitrogen and rock cycles. ... Plants and Animal Die. ... how far you drive your car, how much electricity you use (electricity primarily comes from burning coal), where the food...
  • Safety in the Laboratory - Wilson's Web Page

    Safety in the Laboratory - Wilson's Web Page

    HHPS and WHMIS Symbols. Household Hazardous Product Symbols (HHPS) Many products used in our homes may be dangerous if used incorrectly. For this reason, household products are marked with . symbols. that allow us to recognize and interpret potential hazards.
  • BIOMECHANICS APPLICATIONS - Instruct

    BIOMECHANICS APPLICATIONS - Instruct

    Strengthen lateral hip rotators 2. Stretch medial hip rotators Tibia rotated lateral lateral facing patella frequent in MALES treatment: - muscular balance in all 3 hamstrings must be developed Key Features of Good Shoes Heel well cushioned Heel Counter firm...
  • EB 711 Lecture 8 - Medical University of South Carolina

    EB 711 Lecture 8 - Medical University of South Carolina

    Nested case-control studies are a logical extension of cohort studies and an efficient way to learn about associations. Design of nested studies is as strong as cohort studies. General Definition: Case-Control Study. A method of sampling a population in which:
  • Writing Skills - St Cuthbert Mayne GCSE English

    Writing Skills - St Cuthbert Mayne GCSE English

    Writing Skills 3. Writing to inform and Newspaper articles. ... we can use CONNECTIVES or PUNCTUATION. Joining clauses and simple sentences. CONNECTIVES. But. However. Because. ... (might be more than one paragraph) Para 2. The effect it would have on...
  • Chapter I. Introduction Naval Architecture: the science and

    Chapter I. Introduction Naval Architecture: the science and

    Chapter I. Introduction I. Category of Ocean Vehicles By Support (restoring) Forces -Supported by buoyancy force - Conventional displacement ship - Supported by Hydrodynamic force - Hydrofoil ships and Planning Hull ships, at Full Speed.
  • Forensic Anthropology - Mr. Korczak's Science Page

    Forensic Anthropology - Mr. Korczak's Science Page

    Forensic Anthropology: Studying Bones http://people.stu.ca/~mclaugh/skeleton8a.GIF
  • Module 3: Les ondes sonores

    Module 3: Les ondes sonores

    Exemple #2 (p.444) RA: Calcule la vitesse d'une onde. Calcule la vitesse d'une onde sonore qui s'éloigne du diapason de l'exemple 1 si la longueur d'onde d'un cycle est de 275 cm.