First, parse the shared body and size mode.
In the C language, several different variables share the same memory structure, which is called the "shared body" structure. The Memory Length occupied by the shared body variable is equal to the length of the longest member.
The general form of defining a shared object type variable is:
Union shared body name
{
Member Columns
} Variable table column;
In the big-end format, the high byte of word data is stored in the low address, while the low byte of word data is stored in the high address. The small-end format is opposite to the big-end storage format.
The use of union is affected by the system size. For example, the storage formats of the following shared body variables in the large-end mode and small-end mode are as follows:
Union check
{
Int I;
Char c;
} Cc;
Big end mode:
Int I = 1;
Low address and high address
Small-end mode:
Int I = 1;
High address and low address
From the above analysis, you can write the following code to determine the size of the Terminal Mode:
# Include <stdio. h>
Int checkSys ()
{
Union check
{
Int I;
Char c;
} Cc;
Cc. I = 1;
Return (cc. c = 1 );
}
Int main ()
{
If (0! = CheckSys ())
{
Printf ("the current system is a small-end system ");
}
Else
{
Printf ("the current system is a big-end system ");
}
Return 0;
}
This article is from the "Ming" blog, please be sure to keep this source http://8010089.blog.51cto.com/8000089/1304437