#define C ((A *)B)
含义:把定义((A *) B)为宏C
((A )B) 含义是把B强制准换为A型的指针
例如:
#define SP ((int*)b)
void main(void){
int b=4;
int *p=SP;
printf("%d\n",p);
}
输出结果是4。这说明用把b这个int数据变量强制成了一个int *型指针,并最后输出了。
这里用最简单的int替换了a,实际上a应该是自建的复杂类型;
如结构体类型;
typedef volatile struct _Ifx_IOM
{
Ifx_IOM_CLC CLC; /**< \brief 0, IOM Clock Control Register */
unsigned char reserved_4[4]; /**< \brief 4, \internal Reserved */
Ifx_IOM_ID ID; /**< \brief 8, IOM Identification Register */
unsigned char reserved_C[16]; /**< \brief C, \internal Reserved */
Ifx_IOM_KRSTCLR KRSTCLR; /**< \brief 1C, IOM Kernel Reset Status Clear Register */
Ifx_IOM_KRST1 KRST1; /**< \brief 20, IOM Kernel Reset Register 1 */
Ifx_IOM_KRST0 KRST0; /**< \brief 24, IOM Kernel Reset Register 0 */
Ifx_IOM_ACCEN1 ACCEN1; /**< \brief 28, IOM Access Enable Register 1 */
Ifx_IOM_ACCEN0 ACCEN0; /**< \brief 2C, IOM Access Enable Register 0 */
Ifx_IOM_ECMCCFG ECMCCFG; /**< \brief 30, IOM Event Combiner Module Counter Configuration Register */
Ifx_IOM_ECMSELR ECMSELR; /**< \brief 34, IOM Event Combiner Module Global Event Selection Register */
Ifx_IOM_ECMETH0 ECMETH0; /**< \brief 38, IOM Event Combiner Module Event Trigger History Register 0 */
Ifx_IOM_ECMETH1 ECMETH1; /**< \brief 3C, IOM Event Combiner Module Event Trigger History Register 1 */
Ifx_IOM_GTMEXR GTMEXR; /**< \brief 40, IOM GTM Input EXOR Combiner Selection Register */
unsigned char reserved_44[52]; /**< \brief 44, \internal Reserved */
Ifx_IOM_FPCESR FPCESR; /**< \brief 78, IOM Filter and Prescaler Cells Rising & Falling Edge Status Register */
unsigned char reserved_7C[4]; /**< \brief 7C, \internal Reserved */
Ifx_IOM_FPCCTR FPCCTR[16]; /**< \brief 80, IOM Filter and Prescaler Cell Control Register */
Ifx_IOM_FPCTIM FPCTIM[16]; /**< \brief C0, IOM Filter and Prescaler Cell Timer Register */
Ifx_IOM_LAMEWC LAMEWC[16]; /**< \brief 100, IOM Logic Analyzer Module Event Window Count Status Register */
unsigned char reserved_140[64]; /**< \brief 140, \internal Reserved */
Ifx_IOM_LAMCFG LAMCFG[16]; /**< \brief 180, IOM Logic Analyzer Module Configuration Register */
Ifx_IOM_LAMEWS LAMEWS[16]; /**< \brief 1C0, IOM Logic Analyzer Module Event Window Configuration Register */
} Ifx_IOM;
#define IOM /*lint --e(923)*/ ((Ifx_IOM*)0xF0035000u)
IOM->CLC.U = 0x00000000;
技术交流请关注公众号:
“教你嵌入式面试求职”