11.3.1 Qualifiers and qualified types

Types in GCC may be qualified with (in C syntax) const, volatile, restrict, _Atomic qualifiers, and with an address space qualifiers.

The following tree.h macros allow accessing each qualifier separately:

TYPE_READONLY

Accesses the const qualification of the given type. Boolean value, true if type is const-qualified.

TYPE_VOLATILE

Accesses the volatile qualification of the given type. Boolean value, true if type is volatile-qualified.

TYPE_RESTRICT

Accesses the restrict qualification of the given type. Boolean value, true if type is restrict-qualified.

TYPE_ATOMIC

Accesses the _Atomic qualification of the given type. Boolean value, true if type is _Atomic-qualified.

TYPE_ADDR_SPACE

Accesses the address space qualifier of a given type. Always present.

The the address space qualifier is represented by the addr_space_t type, and this macro produces a value of that type.

It is a unsigned char, where each value represents a distinct address space. See Adding support for named address spaces, for a description of address spaces.

Unlike with CV qualifiers, an address space qualifier is present on all types. Types not otherwise qualified with a named address space are qualified with the generic address space, which is syntactically an empty string in C.

The generic address space is represented by the ADDR_SPACE_GENERIC constant, which can be tested for using ADDR_SPACE_GENERIC_P. In C, there’s no syntax for the generic address space: all types not otherwise qualified are in the generic address space.

In addition to individual access, it is possible to work with aggregates of qualifiers:

TYPE_QUALS

This macro returns the set of qualifiers attached to a given type. The result is of type qualifier_set (described below) and contains both the cv-qualifiers and address space qualifier.

TYPE_QUALS_NO_ADDR_SPACE

Like TYPE_QUALS, but without the address space qualifier. Thus, this macro returns only the cv-qualifiers, and its result is of type cv_qualifier, described below.

TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC

Like TYPE_QUALS_NO_ADDR_SPACE, but also excluding the _Atomic qualifier, thus returning only the “access” qualifiers (const, volatile, restrict).

The types that represent these aggregates are described in the following sections.

To get the unqualified version of a type, use the TYPE_MAIN_VARIANT macro. It also may be applied to an unqualified type, but it is not always the identity function in that case.

To get the qs-qualified version of a type t if one exists, you can call get_qualified_type with t and qs. The returned type will be qs-qualified, or NULL_TREE if a so-qualified variant does not exist already.

Instead, if you call build_qualified_type, and there is not already a variant with the requisite qualification, it will be built. Thus, build_qualified_type always returns a qs-qualified variant of t.