1: #include <iostream>
2: #include "../lib/unpsunyj.h"
3:
4: int main(int argc, char **argv)
5: {
6: union {
7: short s;
8: char c[sizeof(short)];
9: } un;
10:
11: un.s = 0x0103;
12: std::cout << "un.s =: " << un.s << std::endl;
13: printf("%s: ", CPU_VENDOR_OS);
14: if (sizeof(short) == 2)
15: {
16: if (un.c[0] == 1 && un.c[1] == 3)
17: printf("big-endian\n");
18: else if (un.c[0] == 3 && un.c[1] == 1)
19: printf("little-endian\n");
20: else
21: printf("unknown\n");
22: }
23: else
24: printf("sizeof(short) = %d\n", static_cast<int>(sizeof(short)));
25:
26: return 0;
27: }
28:
.codearea{ color:black; background-color:white; line-height:18px; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys","BitStream Vera Sans Mono", courier,monospace,serif}
.codearea pre{ color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important}
.linewrap pre{white-space:pre-wrap; white-space:-moz-pre-wrap; white-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word; word-break:normal}
.codearea pre.alt{ background-color:#f7f7ff !important}
.codearea .lnum{color:#4f81bd;line-height:18px}
时间: 2024-10-04 04:56:02