您的位置:首页 > 移动开发 > Android开发

结构体的强制类型转化(android中的代码问题)

2013-11-22 20:50 411 查看
分析一下结构体的强制类型转化,远离不太冻

/*
* Copyright (c) 2013 by Giayee co.LTD
* Funcion Discription
* int argc: disp number of arg
* char *argc[]: disp point of every arg
* main: the main enter point of process
* 2013-11-20 by xiezh@giayee.com
*/

#include "stdafx.h"

struct hw_device_t{
int open;
};

struct hw_hello_t{
struct hw_device_t common;
int x;
int y;
};

void open_device(struct hw_device_t **device){
struct hw_hello_t  *hello_device = (struct hw_hello_t *)malloc( sizeof(struct hw_hello_t) );
hello_device->common.open = 99;
hello_device->x = 95;
hello_device->y = 95;

*device = &hello_device->common;
}

int main(int argc, char* argv[])
{
struct hw_hello_t *dev = NULL;
open_device( (struct hw_device_t **)&dev );
cout << dev->common.open << endl;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: