How can I use a program to check the storage mode of the current system?

Source: Internet
Author: User

Please write a C function. If the processor is big_endian, 0 is returned; If little_endian, 1 is returned.

First, according to the above definition of the size-end mode, assume that the int type variable I is initialized to 1.
We can fully utilize the characteristics of the Union data: the starting addresses of all Members are consistent.
The answer is as follows:
Int checksystem ()

{
Union check
{
Int I;
Char ch;
} C;
C. I = 1;

Return (C. CH = 1 );

}
Now you can use this function to test the storage mode of your current system.

Of course, you can also directly view the memory without using a function to determine the storage mode of the current system.

 

Peer about big end small end detailed explanation http://blog.163.com/law_abidingcamel/blog/static/114132654200932010282750/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.