如何对无效进行类型转换* [英] How do I typecast for void *

查看:61
本文介绍了如何对无效进行类型转换*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想强调个人结构。

但我不知道如何进行类型转换。

有人来解决这个问题吗?





i want to typecast personal structure.
but i dont know how do i typecast.
is anyone to solve this problem?


typedef struct _data_type
{

	INT	   n;
	BOOL   b;
	double db;
	DWORD  dw;
	DOUBLE DB;
	
}DATATYPE;

#define CAST(data,str) (##str##*##)##data

void * data;
str ="DATATYPE"

CAST(data,str);





我的尝试:



不可能吗?请回答我的问题。



What I have tried:

is it impossible? plz, answer my question.

推荐答案

我假设您使用的是 C 编程语言(自 typedef C ++ struct 之前不需要。



C 编程语言中,演员阵容可以写成

I assume you are using C programming language (since typedef before struct isn't necessary in C++).

In C programming language, the cast could be written
void * data;
DATATYPE * d0 = (DATATYPE *) data;





因此你的宏将成为



Hence your macro would become

#define CAST(data, DATATYPE)  (DATATYPE*)(data)





用法:



Usage:

DATATYPE * d1 = CAST(data, DATATYPE);





但是,我质疑这种宏的用处。



However, I question the usefulness of such a macro.


这篇关于如何对无效进行类型转换*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆