标签:野指针 stat ann 结构 log typedef sub c语言 priority
关于Pointer,一定要杜绝“野指针”!下面的代码中定义了一个指向NVIC_InitTypeDef结构体类型的指针,但是并没有用“一块内存地址”来初始化该指针,因此是一个野指针!
由于没有被初始化,该指针可能指向内存的任何地方,包括0X00000000,由此带来的后果是对该指针的一切间接引用都是非法的,很有可能修改内存中代码区/数据区的数据。一定要杜绝使用这种指针!
static void EXTI_NVIC_Config(void){ NVIC_InitTypeDef *NVIC_InitStruct; /* .2 */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStruct ->NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStruct ->NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStruct ->NVIC_IRQChannelSubPriority = 1; NVIC_InitStruct ->NVIC_IRQChannelCmd = ENABLE; /* .3 */ NVIC_Init(NVIC_InitStruct); }
下面是更改后的代码:
static void EXTI_NVIC_Config(void){ NVIC_InitTypeDef NVIC_INIT_S; NVIC_InitTypeDef *NVIC_InitStruct = &NVIC_INIT_S; /* .2 */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStruct ->NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStruct ->NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStruct ->NVIC_IRQChannelSubPriority = 1; NVIC_InitStruct ->NVIC_IRQChannelCmd = ENABLE; /* .3 */ NVIC_Init(NVIC_InitStruct); }
标签:野指针 stat ann 结构 log typedef sub c语言 priority
原文地址:http://www.cnblogs.com/alexboo/p/6682482.html