const volatile INT i

Source: Internet
Author: User

Problem:

const volatile int i=10; Is there a problem with this line of code? If not, what is the nature of that I?

Reply:

No problems, such as read-only status registers. It is volatile because it can be changed unexpectedly; it is const because the program should not attempt to modify it.

Volatile and const are not contradictory, but the scope of control is not the same, one is outside the program itself, the other is the program itself.

Const represents (runtime) constant semantics: const-decorated objects cannot be modified at their scope, and the compiler generates compilation errors for expressions that attempt to directly modify the const object.

Volatile means "volatile", that is, the runtime object may be modified outside the control flow of the current program context (for example, multiple threads are modified by other threads; the memory where the object resides may be randomly modified by multiple hardware devices, etc.)

: A volatile object that the compiler does not optimize for the operation of this object. An object can be modified at the same time by both const and volatile, indicating that the object embodies constant semantics, but it may be modified by an unexpected situation in the context of the program in which the current object resides.

const volatile INT i

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.