问题描述
我想看看这段代码是否适用于Big-Endian
系统。另外,如果有人对如何在编译时确定这一点有任何想法,以便我使用正确的解码或编码功能,我将非常感谢帮助。
谢谢,
$ b $bChé
#include< iostream>
int main( int argc,char * argv [])
{
//默认系统到小端
bool isLittleEndian = true;
//检查这个平台是big-endian还是little endian
wchar_t a = L''a'';
unsigned char * testChar = reinterpret_cast< unsigned char *>(& a);
// Big Endian在此输出中不显示任何内容
std :: cout< ;< (unsigned char *)testChar<< std :: endl;
if(testChar == 0)
{
isLittleEndian = false;
// Big Endian应显示''" Big Endian Success"这里
std :: cout<< Big Endian成功 << std :: endl;
返回0;
}
我非常感谢你的帮助。至少有一个愚蠢的错误,因为我复制并将代码添加到main而不进行测试。你对我不知道的一些问题完全正确。
。我的
愿意这样做是出于不确定性。我想制作
便携式unicode处理函数,可直接与
说一个人随便输入C ++ const wchar_t * L" Hello World"
无忧无虑。
感谢您的帮助。
哦,好主耶稣没有!
有完全可移植的方法,这不是一个
他们!
查看我最近在comp.std.c上发布的一些代码。
-
Frederick Gotham
I want to see if this code works the way it should on a Big-Endian
system. Also if anyone has any ideas on how determine this at
compile-time so that I use the right decoding or encoding functions, I
would greatly appreciate the help.
Thanks,
Ché
#include <iostream>
int main( int argc, char* argv[] )
{
// Default system to little endian
bool isLittleEndian = true;
// Check whether this platform is big-endian or little endian
wchar_t a = L''a'';
unsigned char* testChar = reinterpret_cast<unsigned char*>( &a );
// Big Endian should display nothing on output here
std::cout << (unsigned char*) testChar << std::endl;
if( testChar == 0 )
{
isLittleEndian = false;
// Big Endian should display ''"Big Endian Success" here
std::cout << "Big Endian Success" << std::endl;
return 0;
}
I really appreciate your help. There was at least one silly mistake as
I copied and added the code to main without testing. You are
completely correct on some of the issues that I was unaware of. My
desire to do this was formed out of uncertainty. I want to make
portable unicode handling functions that can interface directly with
say a person typing casually into C++ the const wchar_t* L"Hello World"
without worry.
Thank you for your help.
Oh good lord Jesus no!
There are perfectly portable ways of doing this, and this is not one of
them!
Check out some code I posted recently on comp.std.c++
http://groups.google.ie/group/comp.s...4a21366?hl=en&
--
Frederick Gotham
这篇关于请有人在Big-Endian系统上测试这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!