CompuServe Thread

#GURU errors

6 messages in this thread
#373From: Henry WilliamsSep 13, 1990 3:02 PM
Hello, Was hoping someone could give me an idea what's going wrong with my program. What I have done is initialize an array a[30][60] containing a maze. Using the switch command with 8 compass points (n,se, etc.), I print out a 14 x 7 maze of array `a' depending on which compass pt typed in. ** The problem is this…I can start the program with no trouble. All seems to be working well for about ten moves, then I GURU with a cpu trap, address error (00000003.). I've tried passing the array between functions, and I've tried a global variable with the same outcome. I tried to allocate memory for the array and successfully got rid of the address error only to get a GURU 0000000B. which is a cpu line B trap (OpCode 1011) and I don't have a single idea what it means or how to fix it. I am running this program from the CLI window for now and I'm using a Manx 3.6a compiler. Thanks in advance. Henry
#375From: Mike Spille/ManxSep 13, 1990 3:34 PM
What's the array decl and the code referencing the array look like? It sounds like you're not allocating the array correctly & you end up referecing uninitialized stuff. -Mike
#392From: Don Curtis/SYSOPSep 13, 1990 10:25 PM
Henry, My first guess is that you've got an index that's getting out of bounds of the array. Perhaps it's not being re-zero'ed or you're making a very common mistake….the array size of 30×60 means your maximum index values would be 29 x 59. The fact that things changed when you allocated memory for the array rather than using declared arrays…would also indicate that your indexing into the array is the problem. Don
#465From: Henry WilliamsSep 15, 1990 6:05 PM
Hello Don, I'm aware that the array starts at 0 and have checked to make sure it works right by putting the array through a double loop that printed the array in the right pattern. I'm not quite sure what you mean by re-zero'ed. What happens though is that I want the program print function to draw part of my maze at a time, not necessarily start back at a[0][0]. Using the right syntax of course would it matter if I use calloc or malloc? Thanks for the advice, Henry ps: I have taken precautions to make sure my print function doesn't go past the last array element.
#492From: Don Curtis/SYSOPSep 16, 1990 1:23 AM
Henry, You mentioned that it's only on successive entries into the array that you have a problem…your first entry into it works…or that's the way I understood your message. Thus, while your index into the array may be right the first time thru…going thru it multiple times may cause your index to go out of bounds…depending on how you use the index, and if it is re-set to zero (or some in-bounds number). As an example, using the form: while (a != 29) { do_something(); a++; } can easily get out of bounds, whereas the form: while (a >= 0 && a < 30 ) { do_something(); a++; } If somehow or other, a started out as 30, the first example would loop for quite a while…where the second example would not. continued….
#493From: Don Curtis/SYSOPSep 16, 1990 1:26 AM
continuation… You say you can print the array, and it's ok…what about the function you're using to fill out the array? Does that function stay in bounds? Reading out of bounds more than likely won't cause you any problems…but writing out of bounds will almost always cause a problem. As to calloc() vs malloc()…yes, very definately. calloc() returns a pointer to cleared memory. That is…it's all set to zero. malloc() returns a pointer to memory…it may or may not be all set to zero. Don