这是正确的吗?! [英] Is this the correct?!

查看:81
本文介绍了这是正确的吗?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这是确定处理器是否很少的正确方法

endian或Big endian。

if(( *(char *)& i)== 1)

lil_end = TRUE;

else

lil_end = FALSE;

Hi all,
Is this the corrrect method to determine if the procesor is little
endian or Big endian.
if((*(char*)&i)==1)
lil_end = TRUE;
else
lil_end = FALSE;

推荐答案

va ****** @ rediffmail .com 写道:
这是确定处理器是小端还是大端的正确方法。
if((*(char *)& ; i)== 1)
lil_end = TRUE;

lil_end = FALSE;
Is this the corrrect method to determine if the procesor is little
endian or Big endian.
if((*(char*)&i)==1)
lil_end = TRUE;
else
lil_end = FALSE;




我假设你'我有一个


int i = 1;


以上,不,有*没有*方法确定位顺序C中的类型

注意,我说* bit * order,而不是* byte * order。一个类型可能有任何

位排序它选择它的位顺序相对于另一种类型

可能无法以任何有意义的方式匹配。这将是一个非常愚蠢的,但完全合法的实施。我可以想一想这个测试可以通过或失败的各种方式,它依赖于可能或者可能的行为,但是b $ b不能在下一次运行中给出相同的结果程序。


恕我直言,最好只考虑C签名和未签名

整数类型,保证最小限制,小心不要

溢出/下溢有符号整数类型,而不是试图做任何棘手的事情。



I''m assuming you''ve got a

int i = 1;

above, and no, there is *no* way to determine the bit order of a type
in C. Notice, I said *bit* order, not *byte* order. A type may have any
bit ordering it chooses and its bit order in relation to another type
may not match up in any meaningful way. This would be a pretty stupid,
but perfectly legal implementation. I can think of a tou of ways how
this test can pass or fail and it relies on behavior that may or may
not give the same result on the next run of the program.

IMHO, it''s best to just think of C as having signed and unsigned
integer types with guaranteed minimum limits and being careful not to
overflow/underflow the signed integer types instead of trying to do
anything tricky.


va******@rediffmail.com 写道:
大家好,<这是确定处理器是小端还是大端的正确方法。
if((*(char *)& i)== 1)
lil_end =是的;
其他
lil_end = FALSE;
Hi all,
Is this the corrrect method to determine if the procesor is little
endian or Big endian.
if((*(char*)&i)==1)
lil_end = TRUE;
else
lil_end = FALSE;




嗯,这里肯定有东西丢失(或者我遗漏了一些东西;)) />

你能做什么,是写一个长的(比如0x1234 5678)到内存,并逐字节读取
它(我可以想到至少三个映射,但在你的情况下

只读取第一个字节可能就足够了)。


long l = 0x12345678;


if(*(char *)& l == 0x12)

/ * big endian * /

else

/ * little endian * /


祝你好运,

-

Martijn
http://www.sereneconcepts.nl


va * *****@rediffmail.com 写道:
大家好,
这是确定处理器是小端还是大端的正确方法。
if((*(char *)& i)== 1)
lil_end = TRUE;
其他
lil_end = FALSE;
Hi all,
Is this the corrrect method to determine if the procesor is
little endian or Big endian.
if((*(char*)&i)==1)
lil_end = TRUE;
else
lil_end = FALSE;




请在发布到clc之前阅读常见问题解答...

http://www.eskimo.com/~scs/C-faq/q20.9.html

彼得



Please read the FAQ before posting to clc...

http://www.eskimo.com/~scs/C-faq/q20.9.html

--
Peter


这篇关于这是正确的吗?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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