-qcheck

Description

Generates code that performs certain types of runtime checking. If a violation is encountered, a runtime exception is raised by sending a SIGTRAP signal to the process.

Syntax

Read syntax diagramSkip visual syntax diagram        .-nocheck-------------------------.
>>- -q--+-check--+----------------------+-+--------------------><
                 |    .-:-------------. |
                 |    V               | |
                 '-=----+-all-------+-+-'
                        +-nullptr---+
                        +-nonullptr-+
                        +-bounds----+
                        +-nobounds--+
                        +-divzero---+
                        '-nodivzero-'

where:

all Switches on all the following suboptions. You can use the all option along with the no... form of one or more of the other options as a filter.

For example, using:

xlc++ myprogram.C -qcheck=all:nonullptr

provides checking for everything except for addresses contained in pointer variables used to reference storage.

If you use all with the no... form of the options, all should be the first suboption.

NULLptr | NONULLptr Performs runtime checking of addresses contained in pointer variables used to reference storage. The address is checked at the point of use; a trap will occur if the value is less than 512.
bounds | nobounds Performs runtime checking of addresses when subscripting within an object of known size. The index is checked to ensure that it will result in an address that lies within the bounds of the object's storage. A trap will occur if the address does not lie within the bounds of the object.

This suboption has no effect on accesses to a variable length array.

DIVzero | NODIVzero Performs runtime checking of integer division. A trap will occur if an attempt is made to divide by zero.

See also #pragma options.

Notes

The -qcheck option has several suboptions, as described above. If you use more than one suboption, separate each one with a colon (:).

Specifying the -qcheck option without any suboptions, and without any other variations of -qcheck on the command line, turns all of the suboptions on.

Using the -qcheck option with suboptions turns the specified suboptions on if they do not have the no prefix, and off if they have the no prefix.

You can specify the -qcheck option more than once. The suboption settings are accumulated, but the later suboptions override the earlier ones.

The -qcheck option affects the runtime performance of the application. When checking is enabled, runtime checks are inserted into the application, which may result in slower execution.

Examples

  1. For -qcheck=nullptr:bounds:

    void func1(int* p) {
      *p = 42;             /* Traps if p is a null pointer */
    }
     
    void func2(int i) {
      int array[10];
      array[i] = 42;     /* Traps if i is outside range 0 - 9 */
    }
  2. For -qcheck=divzero:

    void func3(int a, int b) {
      a / b;            /* Traps if b=0  */
    }

Related information