Keil Logo

Technical Support

On-Line Manuals

Compiler User Guide

Preface Overview of the Compiler Getting Started with the Compiler Compiler Features Compiler Coding Practices Compiler Diagnostic Messages Using the Inline and Embedded Assemblers of the AR Compiler Command-line Options Language Extensions Preprocessor extensions #assert #include_next #unassert #warning C99 language features available in C90 // comments Subscripting struct Flexible array members C99 language features available in C++ and C90 Variadic macros long long restrict Hexadecimal floats Standard C language extensions Constant expressions Array and pointer extensions Block scope function declarations Dollar signs in identifiers Top-level declarations Benign redeclarations External entities Function prototypes Standard C++ language extensions ? operator Declaration of a class member friend Read/write constants Scalar type constants Specialization of nonmember function templates Type conversions Standard C and Standard C++ language extensions Address of a register variable Arguments to functions Anonymous classes, structures and unions Assembler labels Empty declaration Hexadecimal floating-point constants Incomplete enums Integral type extensions Label definitions Long float Nonstatic local variables Structure, union, enum, and bitfield extensions GNU extensions to the C and C++ languages Compiler-specific Features C and C++ Implementation Details What is Semihosting? Via File Syntax Summary Table of GNU Language Extensions Standard C Implementation Definition Standard C++ Implementation Definition C and C++ Compiler Implementation Limits

Read/write constants

8.28 Read/write constants

A linkage specification for external constants indicates that a constant can be dynamically initialized or have mutable members.


The use of "C++:read/write" linkage is only necessary for code compiled with --apcs /rwpi. If you recompile existing code with this option, you must change the linkage specification for external constants that are dynamically initialized or have mutable members.
Compiling C++ with the --apcs /rwpi option deviates from the ISO C++ Standard. The declarations in this example assume that x is in a read-only segment:
extern const T x;
extern "C++" const T x;
extern "C" const T x;
Dynamic initialization of x including user-defined constructors is not possible for constants and T cannot contain mutable members. The new linkage specification in this example declares that x is in a read/write segment even if it is initialized with a constant. Dynamic initialization of x is permitted and T can contain mutable members. The definitions of x, y, and z in another file must have the same linkage specifications.
extern const int z;                   // in read-only segment, cannot
                                      // be dynamically initialized
extern "C++:read/write" const int y;  // in read/write segment
                                      // can be dynamically 
                                      // initialized 
extern "C++:read/write"
    const int i=5;                    // placed in read-only segment,
                                      // not extern because implicitly
                                      // static 
    extern const T x=6;               // placed in read/write segment
    struct S
        static const T T x;           // placed in read/write segment
Constant objects must not be redeclared with another linkage. The code in the following example produces a compile error.
extern "C++"  const T x;
extern "C++:read/write"  const T x; /* error */


Because C does not have the linkage specifications, you cannot use a const object declared in C++ as extern "C++:read/write" from C.
Non-ConfidentialPDF file icon PDF versionARM DUI0375H
Copyright © 2007, 2008, 2011, 2012, 2014-2016 ARM. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.