相关疑难解决方法(0)

模仿/模仿C中的大端行为?

我想知道是否有可能模仿一个大端行为,用于测试目的?

通过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)

c gcc mingw

17
推荐指数
2
解决办法
8376
查看次数

在没有真正的大端处理器的情况下测试大端

我想在 Windows(在 x86-64 上)测试我的 c 代码的 big endian。我们应该怎么做?

c endianness

2
推荐指数
1
解决办法
1590
查看次数

标签 统计

c ×2

endianness ×1

gcc ×1

mingw ×1