大小端测试程序

500阅读 0评论2014-12-07 644924073
分类:C/C++

1. 大小端测试程序
  1. #include<stdio.h>
  2. //return 0 is big_endian return 1 is small endian
  3. int checkSystem()
  4. {
  5.     union check
  6.     {
  7.         int i;
  8.         char ch;
  9.     }c;
  10.     c.i = 1;
  11.     return (c.ch == 1);
  12. }

  13. int main()
  14. {
  15.     int j = 0;
  16.     j = checkSystem();
  17.     printf("ret=%d\n",j);
  18.     printf("return 0 is big_endian return 1 is small endian\n");
  19.     return 0;
  20. }
Makefile
  1. #CC=gcc
  2. CC=arm-linux-gcc
  3. CFLAGS= -g -Wall
  4. TAR= big_little

  5. ALL: $(TAR)

  6. big_little:big_little.c
  7. $(CC) $(CFLAGS) -o $@ $^



上一篇:【shell】一些编程的小技巧(未完成)
下一篇:关于linux kernel编译的几项关键点