检查系统字节顺序 little endian OR big endian

#include <iostream>

void checkEndian()
{
	union checker
	{
		int fourBytes;
		char oneByte;
	};

	checker c;
	c.fourBytes = 1;

	if(c.oneByte)
		std::cout << "Little endian\n";
	else
		std::cout << "Big endian\n";

};

int main()
{
	checkEndian();

	return 0;
}

你可能感兴趣的:(include)