kent logo

CO538 Anonymous Questions and Answers Keyword Index

This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.

To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

Keyword reference for q5


Question 51 (2004):

I have started Q5 and was wondering if you could give any tips on how to convert a character to upper case. And also what you mean on flushing and how to do this.

Answer 51:

Just as a side-note, Q5 is not for assessment -- but doing it anyway yourself is useful! There are essentially two ways to convert between lower and upper case characters. The first is to do it arithmetically (since `BYTE's can be treated as regular values):

    upper.char := (lower.char - 'a') + 'A'

Of course, you'd better check that `lower.char' really is in the range `a' to `z' first. The second method is more cunning, and relies on the way ASCII characters are assigned:

    upper.char := lower.char /\ #DF

For flushing, see the answer to Question 91 (2000).

Keywords: q5 , flush


Question 46 (2003):

I'm having trouble with the `overflow.buffer' process in q5. Here is what I have; there seems to be a problem with `count' such that it doesn't get incremented and nothing ever gets outputted. Thanks.

    [adjusted code]

    PROC overflow.buffer (...)
      [BUFSIZE] BYTE Buffer:
      INT head, tail, count:
        head:= 0
        tail:= 0
        INT count:
        count := 0
        WHILE TRUE
          ...  do things

Answer 46:

Inside the body of the WHILE loop, `count' is undefined [1]. The assignment `count := 0' is assigning to the `count' declared immediately above it. In occam, the scope of a variable is the process that follows it. Assignment is a process (simple), as are SEQ blocks, etc. (processes that contain sub-processes). Thus, the scope of the first `count' declaration is the entirity of the SEQ body (in effect, all the code in `overflow.buffer'). When `count' is declared again inside the SEQ, it descopes the earlier `count'. The scope of this is, as always, the process that follows it, which is just the single assignment `count := 0', which of course leaves the earlier `count' untouched.

  1. By default, the occam workspace is initialised to 0x80000000 (MOSTNEG INT). Thus, count will likely be this value -- but it should always be considered undefined (with an unknown value). The Linux version of KRoC now has an undefined usage checker which will spot these sorts of error. Pre-releases of KRoC/Linux are better at this sort of thing.

Keywords: q5 , variable-scope

Valid CSS!

Valid XHTML 1.0!

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Last modified Mon May 20 13:50:31 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.