XML

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 csub0

2008

Question 27 (2008):

Submission reference: IN1631

I'm getting a runtime error: CSUB0 at or around this code:

  INITIAL INT l.offset IS (id * 4) - 1:
  INITIAL BYTE r.off IS BYTE r.offset:

where id is an INT I'm then attempting to add r.off to another BYTE value in cursor.x.y. I'm essentially trying to cast an INT to a BYTE value. The INT value should be in the range 0-255, so I'm not sure what the problem is I'm encountering.

Answer 27:

First, apologies for the dreadful name (CSUB0) in the error message! CSUB0 is one of the byte codes generated by the occam compiler. Its used for checking ranges: array indices, CASE input tags, type range violations (e.g. for BYTEs). The latter is probably what's happening here.

So long as 0 < id ≤ 64, then 0 ≤ l.offset &le 255 and casting it to a BYTE will be OK.

However, if id were ever to be zero, then l.offset would be -1 and casting it to a BYTE would be illegal and raise an error.

You do, though, cast something called r.offset in the code you quote and say nothing about its value. Might this be your error?

Assuming the casting of r.offset to (your BYTE variable) r.off worked, adding some BYTE (e.g. r.off) to some other BYTE value may overflow (i.e. result in a number greater than 255).

Keywords: q7 , csub0

2007

Question 49 (2007):

Submission reference: IN1376

I am currently doing the Cylons assesment and I have encountered the CSUB0 error. Is there any place where I can find what that error means? Or can you explain me the cause of such error?

The error is in the function:

    ...  code omitted

Answer 49:

We're sorry about this low-level error message! It will be changed. CSUB0 is one of the BYTE-codes in the intermediate language generated by the occam-pi compiler and which the Transterpreter interptrets. It is the instruction generated to check that numbers (usually array indices) are within certain bounds. So, it almost always means an array bounds violation.

You pointed in your code snippet to the line on which the run-time system told you contained the error. That line has a reference to an array element. The index in that reference has gone out of bounds – your code has a bug.

As it says at the top of this page, this is not a forum for debugging your code. However ... you might check your min.index function, which return the minimum range and not the index of the minimum range. Also, in your left.to.center function (once you've fixed the above problem), the index will still go out of range if, for instance, your min.index parameter was equal to MID.RAY.

Keywords: cylons , stop , csub0

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:26 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.