プロジェクトで、次の定義を持つヘッダー ファイルを使用していました。
#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
、別のヘッダー ファイルで次のように使用されます。
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)
私の質問は__I
、C++ ではなく C で const になるのはなぜですか? アドレスがあるので CR が指している値を変更することはできますが、の定義__I
が異なる理由は好奇心です。
これが何のために、または何からのものであるかに興味がある人のために、__I
定義は IAR Embedded Workbench ARM for Cortex-M4 からのものであり、構造体は Texas Instruments LM4F120H5QR CMSIS ファイルからのものです。