-qroptr

Category

Object code control

Pragma equivalent

None.

Purpose

Specifies the storage location for constant pointers.

When -qroptr is in effect, constant pointers are placed in read-only storage. When -qnoroptr is in effect, pointers are placed are placed in read/write storage.

Syntax

Read syntax diagramSkip visual syntax diagram
        .-noroptr-.   
>>- -q--+-roptr---+--------------------------------------------><

Defaults

-qnoroptr

Usage

A constant pointer is equivalent to an address constant. For example:
int* const p = &n;

When -qnoroptr is in effect, you can change the values of constant pointers without generating errors.

The -qroptr can improve runtime performance, save storage, and provide shared access, but code that attempts to modify a read-only constant value generates a memory error. For example, assume the following code, which attempts to change the address that c1_ptr points to:
char c1 = 10;
char c2 = 20; 
char* const c1_ptr = &c1;

int main() {
    *(char**)&c1_ptr = &c2; 
}
Compiling this code with the -qroptr option specified will result in a segmentation fault at run time.

You should not use -qroptr for compiled code that will become part of a shared library.

Predefined macros

None.

Related information