Describe the address-space layout (highlighting four areas of memory) of a typical compiled x86 C program, and how each of these areas are used by C constructs. [8 marks] (d) Briefly explain what undefined behaviour is in the C standard. Under what circumstance(s) would calling the following C function result in undefined behaviour? int32_t divide(int32_t a, int32_t b) { return a / b; } [4 marks] 2 CST.2016.3.3 2 Programming in C and C++ (a) Consider unspecified behaviour in C. (i) Define what unspecified behaviour means in the C standard and give two examples of such behaviour. [3 marks] Objects:; ArrayList w = new ArrayList<>(10); Explain any differences in behaviour between assignments v1 = w and v2 = w and also between method calls v1.set(4,n) and v2.set(4,n). [4 marks] 6 CST.2016.3.7 6 Further Java (a) Describe the operation of wait() and notifyAll(). Ensure that your answer explains when locks are acquired and released. [5 marks] (b) A future is a mechanism to store the eventual result of a computation done in another thread. The idea is that the computation is run asynchronously and the calling thread only blocks if it tries to use a result that hasn’t been computed yet. An example program using a future is shown below. Future f = new Future() { @Override public String execute() { // …long running computation… return data; }; // … String result = f.get(); // blocks if execute() unfinished Use wait() and notifyAll() to provide an implementation of the Future class that would work with the example program above. [10 marks] Explain what specular and diffuse reflection are in the real world. State and explain equations for calculating approximations to both in a computer. [8 marks] 5 [TURN OVER CST.2004.13.6 6 Compiler Construction (a) Explain the differences (illustrating each with a small program) between (i) static and dynamic binding (scoping); [4 marks] (ii) static and dynamic typing. [2 marks] (b) Java is sometimes said to be “dynamically typed” in that a variable whose type is (class) C can be assigned a value of (class) D provided that D extends C; conversely a variable of type D can be assigned a value of type C using a cast. By considering storage layouts, explain why the former assignment is always valid and the latter sometimes invalid. [4 marks] Critique and test procedures to validate the efficiency and effectiveness of users’ interactions with computer systems
how user interactions might evolve for emerging, particularly immersive, technologies. (c) Suppose that the following rules are proposed as possible optimizations to be implemented in your compiler. expression simplifies to expression (fst e, snd e) → e fst (e1, e2) → e1 snd (e1, e2) → e2 Describe how you could implement these rules so that the simplifications are made only when the program’s semantics is correctly preserved. [5 marks] 5 (TURN OVER) CST.2016.3.6 5 Concepts in Programming Languages (a) Explain what is meant by a monad in a programming language, giving the two fundamental operations of a monad along with their types. [3 marks] (i) What scheduling problem could arise here? [2 marks]