Re: [問題] 判斷Big Endian系統 or Little Endian系統
※ 引述《loveme00835 (恋さや)》之銘言:
: 如果要測試,我推薦用大於1Byte的型態,函式變成這樣:
: bool IsBigEndian()
: {
: short val = 0x1234;
: char *p = reinterpret_cast<char*>(&val);
: return (*p==0x12);
: }
剛剛查了union,原來有匿名用法,借用l大的函式改成下面的樣子。
bool IsBigEndian()
{
union {
short int i;
char ch;
};
i = 0x1234;
return (ch==0x12);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.121.137.166
※ 編輯: tsaiminghan 來自: 59.121.137.166 (08/28 10:29)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 4 篇):