设为首页 加入收藏

TOP

静态的声明一个指针变量
2013-01-01 14:50:35 来源: 作者: 【 】 浏览:353
Tags:静态 声明 一个 指针 变量

    我是从Android的GPS模拟器代码中看到的,觉得很有意思,就记录下来了

    首先是结构体的定义:

    [cpp]

    /* this is the state of our connection to the qemu_gpsd daemon */

    typedef struct {

    int                     init;

    int                     fd;

    GpsCallbacks            callbacks;

    pthread_t               thread;

    int                     control ;

    } GpsState;

    /* this is the state of our connection to the qemu_gpsd daemon */

    typedef struct {

    int                     init;

    int                     fd;

    GpsCallbacks            callbacks;

    pthread_t               thread;

    int                     control ;

    } GpsState;

    然后声明结构体指针变量

    static GpsState  _gps_state ;

    正常使用:

    [cpp]

    static int

    qemu_gps_init(GpsCallbacks* callbacks)

    {

    GpsState*  s = _gps_state;

    if (!s->init)

    gps_state_init(s, callbacks);

    if (s->fd < 0)

    return -1;

    return 0;

    }

    static int

    qemu_gps_init(GpsCallbacks* callbacks)

    {

    GpsState*  s = _gps_state;

    if (!s->init)

    gps_state_init(s, callbacks);

    if (s->fd < 0)

    return -1;

    return 0;

    }

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇让C++支持interface 下一篇C ++标准库容器总结

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: