summaryrefslogtreecommitdiff
path: root/check-endian.cpp
blob: c4bd6f2a6bb67940bb3538a598262efaeb8029e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

#include <cstdlib>
#include <iostream>

using namespace std;

union endian_check
{
    int  number;
    char check;
};

int main(int argc, char** argv)
{
    endian_check _check;
    _check.number = 1;

    // Check the valu of the least significant byte.
    if (_check.check)
        cout << "little endian" << endl;
    else
        cout << "big endian" << endl;

    return EXIT_SUCCESS;
}