Byte order 검출 이론

Programming/C/C++ 2007/05/08 12:21 장인정신
이것은 자신의 시스템에 대하여 byte order 가 어떻게 되는지 검출하는 겁니다.

x86 계열에서는 little endian 으로 검출될것이고
PPC, mips 계열에서 실행하면 big endian으로 검출되겠지요.

코드:

/*
Copyright (C) Information Equipment co.,LTD.
All rights reserved.
Code by JaeHyuk Cho <mailto:minzkn@infoeq.com>
CVSTAG="$Header$"
*/

#include <stdio.h>

int main(void)
{
static const unsigned char cg_value[sizeof(int)] = {1, 0, };
if((*((int *)(&cg_value[0]))) == 1)
{
  (void)fprintf(stdout, "little endian\n");
}
else
{
  (void)fprintf(stdout, "big endian\n");
}
return(0);
}

/* End of source */
2007/05/08 12:21 2007/05/08 12:21
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.minzkn.com/rss/response/69

댓글+트랙백 ATOM :: http://blog.minzkn.com/atom/response/69

트랙백 주소 :: http://blog.minzkn.com/trackback/69

트랙백 RSS :: http://blog.minzkn.com/rss/trackback/69

트랙백 ATOM :: http://blog.minzkn.com/atom/trackback/69

댓글을 달아 주세요

댓글 RSS 주소 : http://blog.minzkn.com/rss/comment/69
댓글 ATOM 주소 : http://blog.minzkn.com/atom/comment/69