您的位置:首页 > 其它

测试系统的大小印第安序

2015-06-05 22:31 246 查看
直接贴代码了:

#include <stdio.h>

typedef unsigned char BYTE;

int main(void) {

unsigned int num, *p;

p=#

num=0;

*(BYTE *)p=0xff;

if(num==0xff){

printf("its little");

}

else{

printf("its big");

}

return 0;

}

一般X86,ARM是小。

num
is
an
unsigned
 int


p
is
a pointer to that same int.

(BYTE*)p
means "pretend
its really a pointer to a byte instead".

*(BYTE*)p
 =
means "Go set that byte to be the value on the RHS."

the value on the RHS is
0xFF
.

Result: num is a 4-byte integer.

One byte of that int will be set to
0xFF


(it could be the high-byte or the low-byte depending on your platform)

So
num
will
either end up being
0xFF
 00 00 00
, or possibly
0x00
 00 00 FF
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: