INT_MIN and overflow

Source: Internet
Author: User
I haven't updated it after a long time, because I am learning about PL and compiler interpreters. I'm curious about this. because I haven't learned any relevant courses, I have to learn a little hard work and slow progress, so I have nothing to write. Today, we can see that the 32-bit int type ranges from 2147483647 to-2147483648. However, in the CC ++ language, you cannot directly use-2147483648 to replace the minimum negative number,

I haven't updated it after a long time, because I am learning PL and compiler/interpreter knowledge. I'm curious about this. because I haven't learned any relevant courses, I have to learn a little hard work and slow progress, so I have nothing to write.
Today, we see a passage like this:
The value of 32-bit int type is 2147483647 to-2147483648. However, in C/C ++, you cannot directly use-2147483648 to replace the minimum negative number, because it is not a number, but an expression. The expression is: "negative for positive number 2147483648". Therefore, 2147483648 has exceeded. This is why INT_MIN is always defined as (-INT_MAX-1.
I have never paid attention to this before. in the spirit of practice, I ran it on my computer and found that the results were all the same. there was no warning when I started the Wall with gcc. So what is the problem?
Later, a former MSRA employee told me:
In fact, it depends on the standard version ...... If the type of decimal literal is C8 (harmonious) 9, the inferred sequence of decimal literal is long and unsigned long. Therefore, the literal of-21474836 (harmonious) 48 is interpreted as unsigned long, therefore, if it is C ++ 11, it is inferred that the order is long, and long is no problem.
Amount, and the basic knowledge is forgotten.

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.