结构体指针

[复制链接]
2136|7
 楼主| jy02326166 发表于 2013-1-20 13:55 | 显示全部楼层 |阅读模式
pi, GPIO, IO, gp, ni
    GPIO_InitTypeDef      GPIO_InitStructure;                                                                           
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;      
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;            
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;      
    GPIO_Init(GPIOC,    &GPIO_InitStructure);      

    GPIO_InitTypeDef     * GPIO_InitStructure;                                                                           
    GPIO_InitStructure->GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;      
    GPIO_InitStructure-> GPIO_Mode = GPIO_Mode_Out_PP;            
    GPIO_InitStructure-> GPIO_Speed = GPIO_Speed_50MHz;      
    GPIO_Init(GPIOC,    GPIO_InitStructure);              


  我试了两种方法,上面的可以,下面的为什么不能工作?
reille 发表于 2013-1-20 15:26 | 显示全部楼层
本帖最后由 reille 于 2013-1-20 15:28 编辑

你的指针没有分配实体存储空间,所以是野指针,所以不能正常工作。
huangxz 发表于 2013-1-20 15:27 | 显示全部楼层
指针需要初始化
 楼主| jy02326166 发表于 2013-1-20 16:00 | 显示全部楼层
huangxz 发表于 2013-1-20 15:27
指针需要初始化

* GPIO_InitStructure=0
这样初始化行吗?
或者
GPIO_InitTypeDef     GPIO_InitStructure;           
GPIO_InitTypeDef     *GPIO_InitStructure_p;   
GPIO_InitStructure_p=&GPIO_InitStructure;      
uet_cache 发表于 2013-1-20 16:05 | 显示全部楼层
楼主没事找事做吧。。。别人定义好好的 , 为什么要单独定义指针。。。还是顺着大家常用方法好。。
xiaox314 发表于 2013-1-20 17:02 | 显示全部楼层
:)多半是拿来主义!呵呵!楼主的想法很好~
dami 发表于 2013-1-20 21:53 | 显示全部楼层
GPIO_InitTypeDef      GPIO_InitStructure;              
GPIO_InitTypeDef * pGPIO_InitStructure;
pGPIO_InitStructure =&GPIO_InitStructure;                                                            
pGPIO_InitStructure->GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;      
pGPIO_InitStructure->GPIO_Mode = GPIO_Mode_Out_PP;            
pGPIO_InitStructure->GPIO_Speed = GPIO_Speed_50MHz;      
GPIO_Init(GPIOC,    pGPIO_InitStructure);   
 楼主| jy02326166 发表于 2013-1-20 23:17 | 显示全部楼层
dami 发表于 2013-1-20 21:53
GPIO_InitTypeDef      GPIO_InitStructure;              
GPIO_InitTypeDef * pGPIO_InitStructure;
pGPI ...

嗯 谢谢
结果无误,C语言好久没用了,生疏了。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

35

主题

105

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部
0