Is there a reason to declare something "volatile const" in C, but only "volatile" in C ++?

I used the header file in my project, which had the following definitions (s):

#ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus #define __I volatile /*!< Defines 'read only' permissions*/ #else #define __I volatile const /*!< Defines 'read only' permissions*/ #endif 

__I used in the following header file as follows:

  typedef struct { // more members before __I uint32_t CR; /*!< GPIO Commit*/ // more members after } GPIOA_Type; #define GPIOF_BASE 0x40025000UL #define GPIOF ((GPIOA_Type *) GPIOF_BASE) 

My question is, why __I make const in C, but not in C ++? You can still change the value that CR points to, since you have an address, but just wondering why the __I definition __I different.

For someone interesting, this is for or from, __I is determined from the IAR Embedded Workbench ARM for Cortex-M4, and the structure is from CMSIS Texas Instruments LM4F120H5QR files.

+8
c ++ c cortex-m iar cmsis
source share
1 answer

In C ++, the default const variables in the default file area are associated with static linking, which is undesirable for GPIO with memory mapping. The β€œcorrect” fix for this is the extern keyword, but it cannot be used here, since it is obvious that __I should work with class members as well. Thus, removing const makes the default extern binding.

+7
source share

All Articles