问:reinterpret_cast有未定义的行为? [英] Q: reinterpret_cast with undefined behavior?

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

问题描述




我正在尝试确定系统的字节顺序如下:


int i = 1;

bool is_little = * reinterpret_cast< char *> (& i)!= 0;


但是现在我问自己,根据标准,这种reinterpret_cast的使用是否有效?
有效。 br />

谢谢!

-

jb


(rot13的回复地址,首先解读)

解决方案

签名字符或无符号字符?


ben



我试图确定该系统的字节序如下:

INT I = 1;
布尔is_little = *的reinterpret_cast <字符*> (& i)!= 0;

但是现在我问自己,如果使用reinterpret_cast有效,根据标准。

谢谢!
-
jb

(在rot13回复地址,先解读)



< BLOCKQUOTE>"本" <是****** @ hotmail.com>在留言中写道

news:42 ********************** @ news.optusnet.com.au

int i = 1;
bool is_little = * reinterpret_cast< char *> (& i)!= 0;


signed char或unsigned char?




在我的系统上签名,但为什么这很重要?我正在测试

0 ..

-

jb


(回复地址在rot13,首先解读)




" Jakob Bieling" < AR **************** @ rot13.com> skrev i en meddelelse

新闻:d4 ************* @ news.t-online.com ...



我试图确定系统的字节顺序如下:

int i = 1;
bool is_little = * reinterpret_cast< char *> (& i)!= 0;

但是现在我问自己,如果使用reinterpret_cast是有效的,
根据标准。

谢谢!
-
jb

(回复地址在rot13,先解读)



这完全有效 - 请继续。 char的签名是

在这方面无关紧要。


/ Peter


Hi,

I am trying to determine the endianness of the system as follows:

int i = 1;
bool is_little = *reinterpret_cast <char*> (&i) != 0;

But now I was asking myself, if this use of reinterpret_cast is
valid, according to the Standard.

thanks!
--
jb

(reply address in rot13, unscramble first)

解决方案

signed char or unsigned char?

ben

Hi,

I am trying to determine the endianness of the system as follows:

int i = 1;
bool is_little = *reinterpret_cast <char*> (&i) != 0;

But now I was asking myself, if this use of reinterpret_cast is
valid, according to the Standard.

thanks!
--
jb

(reply address in rot13, unscramble first)



"ben" <be******@hotmail.com> wrote in message
news:42**********************@news.optusnet.com.au

int i = 1;
bool is_little = *reinterpret_cast <char*> (&i) != 0;

signed char or unsigned char?



On my system signed, but why does this matter? I am testing against
0 ..
--
jb

(reply address in rot13, unscramble first)



"Jakob Bieling" <ar****************@rot13.com> skrev i en meddelelse
news:d4*************@news.t-online.com...

Hi,

I am trying to determine the endianness of the system as follows:

int i = 1;
bool is_little = *reinterpret_cast <char*> (&i) != 0;

But now I was asking myself, if this use of reinterpret_cast is valid,
according to the Standard.

thanks!
--
jb

(reply address in rot13, unscramble first)


This is perfectly valid - just go ahead. The signedness of char is
irrelevant in this respect.

/Peter


这篇关于问:reinterpret_cast有未定义的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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