无论ideone.com和codepad.org有小端 architechtures.
我想在Big-Endian架构的某台机器上测试我的代码(例如 - Solaris - 我没有).你知道一些简单的方法吗?
我想知道是否有可能模仿一个大端行为,用于测试目的?
通过Windows或Linux,mingw或gcc.这是一个代码示例,我希望仿真返回大端:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#if CHAR_BIT != 8
#error "Unsupported char size for detecting endianness"
#endif
int main (void)
{
short int word = 0x0001;
char *byte = (char *) &word;
if (byte[0]) printf("little endian");
else printf("big endian");
return 0;
}
Run Code Online (Sandbox Code Playgroud)