Deep understanding of volatile-[original sky] and deep understanding of volatile

Source: Internet
Author: User

Deep understanding of volatile-[original sky] and deep understanding of volatile
All volatile variables are defined on the memory, for example: int I = 10; int j = I; int k = I; I = 10; is the initialization variable, it is stored in the data segment, and uninitialized variables are stored in the bss segment, that is, when I is left, it is stored in the memory j = I. At this time, I is the right value, so the value of I is in the register, j. The value above the register may change the value in the register during compilation due to compiler reasons, then the value obtained by k is not what we want. If volatile int k = I is added, k takes the value from the memory every time, ensuring the correctness of the value.

Sina Blog: http://blog.sina.com.cn/u/2049150530
Csdn blog: http://blog.csdn.net/u011749143
Blog: http://www.cnblogs.com/sky-heaven/
Sina Weibo: Zhang xiaohua -- sky
Know: http://www.zhihu.com/people/zhang-bing-hua

Related Article

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.