整数到pinter转换 [英] integer to pinter conversion

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

问题描述

考虑一个函数:


void * test_func(void)

{

return((void *) - 1 );

}


返回时,整数-1转换为void *。

这是可移植的吗?

Consider a function:

void *test_func(void)
{
return ((void *)-1);
}

While returning, the integer -1 is converted to void *.
Is this portable ?

推荐答案

ju **********@yahoo.co.in 写道:
考虑一个函数:

void * test_func(void)
{
返回((void *) - 1);
}
返回时,整数-1转换为void *。
这是可移植的?
Consider a function:

void *test_func(void)
{
return ((void *)-1);
}

While returning, the integer -1 is converted to void *.
Is this portable ?




编号虽然整数可以转换为指针,但此转换的结果是实现定义的,显而易见的

一个整数常量表达式的异常值为0.


FWIW,你甚至不需要上面代码中的强制转换。


祝你好运。

-

Irrwahn Grausewitz(ir ******* @ freenet .de)

欢迎来到clc: http ://www.ungerhu.com/jxh/clc.welcome.txt

clc faq-list: http://www.faqs.org/faqs/C-faq/faq/

clc频繁答案: http://benpfaff.org/writings/clc



No. While an integer may be converted to a pointer, the result
of this conversion is implementation-defined, with the obvious
exception of an integer constant expression with the value 0.

FWIW, you don''t even need the cast in the code above.

Best regards.
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc frequent answers: http://benpfaff.org/writings/clc


ju ********** @ yahoo。 co.in 写道:

考虑一个函数:

void * test_func(void)
{
返回( (void *) - 1);
}

返回时,整数-1转换为void *。
这是可移植的吗?

Consider a function:

void *test_func(void)
{
return ((void *)-1);
}

While returning, the integer -1 is converted to void *.
Is this portable ?




No.


-

pete



No.

--
pete




Irrwahn Grausewitz写道:

Irrwahn Grausewitz wrote:
ju ********** @ yahoo.co.in 写道:
考虑一个功能:

void * test_func(void)
{
返回((void *) - 1);
}
返回时,整数-1被转换为void *。
这是可移植的吗?
Consider a function:

void *test_func(void)
{
return ((void *)-1);
}

While returning, the integer -1 is converted to void *.
Is this portable ?




FWIW,你甚至不需要代码中的强制转换上面。



No. While an integer may be converted to a pointer, the result
of this conversion is implementation-defined, with the obvious
exception of an integer constant expression with the value 0.

FWIW, you don''t even need the cast in the code above.




整数转换为指针再转回(指向

整数)是否会给出原始整数?



Is the conversion of integer to pointer and back again (pointer to
integer) will give the original integer ?


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

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