Question: Fields of packed records (Example 8.8) cannot be passed by reference in Pascal. Likewise, when passing a subrange variable by reference, Pascal requires that all

Fields of packed records (Example 8.8) cannot be passed by reference in Pascal. Likewise, when passing a subrange variable by reference, Pascal requires that all possible values of the corresponding formal parameter be valid for the subrange:

type small = 1..100; R = record x, y : small; end; packed record x, y : small; end; S = var a : 1..10; b: 1..1000; C : R; d: S; procedure foo (var n : small); begin n := 100; writeln(a); end; a := 2; foo (b); fooUsing what you have learned about parameter-passing modes, explain these language restrictions.

type small = 1..100; R = record x, y : small; end; packed record x, y : small; end; S = var a : 1..10; b: 1..1000; C : R; d: S; procedure foo (var n : small); begin n := 100; writeln(a); end; a := 2; foo (b); foo (a); (* ok *) (* static semantic error ) foo(c.x); (* ok *) foo(d.x); (* static semantic error *)

Step by Step Solution

3.39 Rating (177 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The first restriction avoids alignment problems If fields of packed arr... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Language Pragmatics Questions!