且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

问:reinterpret_cast有未定义的行为?

更新时间:2023-11-08 10:48:04

签名字符或无符号字符?


ben


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

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

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

谢谢!
-
jb

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



"本" <是****** @ 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" &LT; AR **************** @ rot13.com&GT; 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