我如何才能找到我的电脑编程使用C的字节序? [英] How can I find Endian-ness of my PC programmatically using C?

查看:83
本文介绍了我如何才能找到我的电脑编程使用C的字节序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/1001307/detecting-endianness-programmatically-in-a-c-program\">Detecting字节顺序编程的C ++程序

有没有什么库函数可用来找到我的电脑的字节序?

Is there any library function available to find the endian-ness of my PC?

推荐答案

为什么你需要一个图书馆,如果你能找到这样呢? :)

Why you need a library if you can find it like this? :)

int num = 1;

if (*(char *)&num == 1)
{
    printf("Little-Endian\n");
}
else
{
    printf("Big-Endian\n");
}

这篇关于我如何才能找到我的电脑编程使用C的字节序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆