[LC++]Endianess Determination

Manu Anand badboyanand at yahoo.com
Mon Sep 3 06:53:29 UTC 2001


Hi
Consider this ques from C faq.

20.9:	How can I determine whether a machine's byte
order is big-endian
	or little-endian?

A:	One way is to use a pointer:

		int x = 1;
		if(*(char *)&x == 1)
			printf("little-endian\n");
		else	printf("big-endian\n");

	It's also possible to use a union.

	See also question 10.16.

	References: H&S Sec. 6.1.2 pp. 163-4.

As should be obvious it makes enormous sense to get
the FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
ftp://snurse-l.org/pub/acllc-c++/faq

HTH
--Manu

__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com



More information about the tuxCPProgramming mailing list