I was using a header file in my project that had the following define(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
The __I
is used as follows in another header file:
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 would the __I
be made const in C but not in C++? You can still modify the value CR is pointing to since you have the address, but am just curios why the definition of __I
is different.
For anybody interested what this is for or from,
the __I
defines are from IAR Embedded Workbench ARM for Cortex-M4
, and the struct is from Texas Instruments LM4F120H5QR CMSIS files.
const
confers internal linkage. I don't know whether it does in C, but I suspect not. Anyway, note that__I
is a name reserved to the implementation, and should not be used in user code.volatile const CR
means you can't useCR
to modify the register; of course it can be modified in other ways