ContentsIndexPreviousNext

6.4.1 Memory Access Violations

If your program tries to access a portion of memory that is protected by the operating system, ACUCOBOL-GT generates a memory access violation message and shuts down.

The most common cause of this violation is indexing beyond the legal range of a table. Often this sort of error is difficult to detect, because it can be data-dependent, as shown in this example:

PERFORM UNTIL IDX > NO-OF-EMPLOYEES
   DISPLAY "EMPLOYEE NAME:   ", EMP-TABLE(IDX)
   ADD 1 TO IDX
END PERFORM.

If NO-OF-EMPLOYEES ever exceeded the size of EMP-TABLE, or if IDX were ever set to zero, you could get a memory access violation when the program is run.

To uncover this type of memory access violation, use the "-Za" compile-time option while you are debugging your program. When you run a program that has been compiled with "-Za", ACUCOBOL-GT prints a subscript out of bounds error message, detailing the legal range of indexes for any table-indexing error that it encounters. (Note that the subscript out of bounds error appears when you run the program, not when you compile it.) You can then correct the program as necessary.

A memory access violation can also occur if there is a bug in any C routine linked into the runtime. Because of the nature of C, the violation can occur long after the called C function executes. There is no easy way to tell if the C routine is the cause. If possible, run the offending COBOL program without linked C routines, using the runtime as distributed by Acucorp.

On MS-DOS you are allowed to address any portion of RAM, including the area where DOS itself resides. Thus, even though the same situations may occur on MS-DOS (such as a table indexed beyond its legal range), no memory access violation messages are generated in that environment. If you are encountering unexpected behavior with your application, you might try compiling with "-Za" to determine whether any table-indexing errors exist in your code. Because MS-DOS does not report memory access violations, programs that work fine under MS-DOS may fail with a memory access violation when they are moved to a UNIX environment.