__ro_placement
Syntax
See Syntax for object attributes.
Unlike most object attributes, when ‑‑ropi is enabled the __ro_placement attribute must be specified both when a data object is defined and when it is declared.
Description
The __ro_placement attribute specifies that a data object should be placed in read-only memory. There are two cases where you might want to use this object attribute:
Data objects declared
const volatileare by default placed in read-write memory. Use the__ro_placementobject attribute to place the data object in read-only memory instead.In C++, a data object declared
constand that needs dynamic initialization is placed in read-write memory and initialized at system startup. If you use the__ro_placementobject attribute, the compiler will give an error message if the data object needs dynamic initialization.
You can only use the __ro_placement object attribute on const objects.
You can use the __ro_placement attribute with C++ objects if the compiler can optimize the C++ dynamic initialization of the data objects into static initialization. This is possible only for relatively simple constructors that have been defined in the header files of the relevant class definitions, so that they are visible to the compiler. If the compiler cannot find the constructor, or if the constructor is too complex, an error message will be issued (Error[Go023]) and the compilation will fail.
Example
__ro_placement const volatile int x = 10;