-qroptr

Description

Specifies the storage location for constant pointers.

Syntax

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

See also: #pragma options.

Notes

This option requires AIX v5.2.

A constant pointer is equivalent to an address constant. For example:

int* const p = &n;

If the default value of -qnoroptr is in effect, constant pointers, virtual function tables, and virtual type tables are placed in read/write storage, and you can change their values without generating errors.

If -qroptr is specified, the compiler places constant pointers, virtual function tables, and virtual type tables in read-only storage. This 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.

Related information