铸字 [英] Typecasting

查看:60
本文介绍了铸字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这些变量:


char * array [2];

void * p;


我怎样才能将p类型转换为数组类型?

Say I have these variables:

char *array[2];
void *p;

how can I typecast p to the type of array?

推荐答案

" Martin Johansen" <毫安****** @ is.online.no>写道:
"Martin Johansen" <ma******@is.online.no> wrote:
说我有这些变量:

char * array [2];
void * p;

我怎样才能将p类型转换为数组类型?
Say I have these variables:

char *array[2];
void *p;

how can I typecast p to the type of array?




p是一个void *。一个人不需要施放无效*。


Richard



p is a void *. One does not need to cast void *s.

Richard




" Richard Bos" ; < rl*@hoekstra-uitgeverij.nl>在消息中写道

news:40 ***************** @ news.individual.net ...

"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:40*****************@news.individual.net...
"马丁约翰森 <毫安****** @ is.online.no>写道:
"Martin Johansen" <ma******@is.online.no> wrote:
说我有这些变量:

char * array [2];
void * p;

我怎样才能将p类型转换为数组类型?
Say I have these variables:

char *array[2];
void *p;

how can I typecast p to the type of array?



p是一个void *。一个不需要转换void * s。



p is a void *. One does not need to cast void *s.




嗯,在这个例子中我这样做,所以当数组作为void指针传递时,

然后输入,编译器仍然可以警告我可能的访问冲突,

,所以我也可以使用sizeof,也可以直接访问数组。所以我确实需要对此进行类型转换,但我看不出它是如何完成的......



Well, in this example I do, so that when array is passed as a void pointer,
then casted, the compiler can still warn me of possible access violations,
and also so I can use sizeof, and also access the array directly. So I do
need to typecast this, but I cannot see how it can be done...


Martin Johansen写道:
Martin Johansen wrote:

Richard Bos < rl*@hoekstra-uitgeverij.nl>在消息中写道
新闻:40 ***************** @ news.individual.net ...

"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:40*****************@news.individual.net...
" Martin Johansen" <毫安****** @ is.online.no>写道:
"Martin Johansen" <ma******@is.online.no> wrote:
>说我有这些变量:
>
> char * array [2];
> void * p;
>
>我怎样才能将p类型转换为数组类型?
> Say I have these variables:
>
> char *array[2];
> void *p;
>
> how can I typecast p to the type of array?



p是一个void *。一个人不需要施放void * s。



p is a void *. One does not need to cast void *s.



嗯,在这个例子中我做



Well, in this example I do




你不能。 C只允许强制转换为标量类型(或无效)。数组

类型不是标量。


Jeremy。



You can''t. C only allows casts to scalar types (or void). Array
types aren''t scalar.

Jeremy.


这篇关于铸字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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