stm32结构体和结构体指针的问题

2019-10-15 17:19发布

本帖最后由 xuesong10210 于 2017-1-14 20:35 编辑

楼主没有理解指针到底是个啥东西!GPIO_InitTypeDef  *GPIO_InitStructure只是定义了一个指针变量。只有当这个指针指向一个具体地方时才能通过指针的方法取出里面的值。GPIO_InitTypeDef  *GPIO_InitStructure系统编译会默认认为定义了一个指向0地址的指针。而GPIO_InitTypeDef GPIO_InitStruct其实是在堆栈区申请了一片能存放GPIO_InitTypeDef结构体变量的空间。
        GPIO_InitTypeDef  *GPIO_InitStructure;
        GPIO_InitTypeDef   GPIO_init;
        
GPIO_InitStructure = &GPIO_init;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
        GPIO_InitStructure->GPIO_Mode=GPIO_Mode_Out_PP;
        GPIO_InitStructure->GPIO_Pin=GPIO_Pin_8;
        GPIO_InitStructure->GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOB, GPIO_InitStructure);
        GPIO_SetBits(GPIOB, GPIO_Pin_8);
通过上面这个做就可以,不过这样做比较多余而已!!!!!!!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。