summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2010-08-23 10:44:41 -0400
committerKohei Yoshida <kyoshida@novell.com>2010-08-23 10:44:41 -0400
commit8ac12eb4a36da290817240edd62cb69f7eab81fd (patch)
treea3013971656050e30b73b458d3e45a6e3ac73171
parenta388be0b4665c88ac2666f688779fdf6a974e80f (diff)
Small program to check the endian-ness of the platform.
-rw-r--r--Makefile4
-rw-r--r--check-endian.cpp21
2 files changed, 25 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..46d65b4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,4 @@
+
+CPPFLAGS=-Wall
+
+check-endian: check-endian.cpp
diff --git a/check-endian.cpp b/check-endian.cpp
new file mode 100644
index 0000000..f355485
--- /dev/null
+++ b/check-endian.cpp
@@ -0,0 +1,21 @@
+
+#include <cstdlib>
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ int num = 1;
+ char* p = reinterpret_cast<char*>(&num);
+ cout << "size of int: " << sizeof(num) << endl;
+ // Check the valu of the least significant byte.
+ int check = static_cast<int>(p[0]);
+ if (check)
+ cout << "little endian" << endl;
+ else
+ cout << "big endian" << endl;
+
+ return EXIT_SUCCESS;
+}
+