C. Volatile

Source: Internet
Author: User

C. Volatile

The volatile parameter is a type modifier. It indicates the type variation that can be changed by unknown factors in some readers.

When volatile is used to determine the volume of variable I, the component will retrieve the value of I from the memory units in the I phase.

No volatile-related variable I may be taken directly from the CPU register when being asked (because I was asked before, that is to say, I was previously taken from the internal memory and saved it to a register.) The reason why I took the value directly from the register rather than in the internal memory, it is because the result of the memory generator's optimized generation of memory (the memory asks the CPU register much faster than the memory asks RAM ).

The regions of the above two types of sentiment are not the same after the region is converted into an alternative region. The reason for this is that the change I may change frequently, and the security certificate determines the issue for the special address.

==========================================================

The volatile parameter is a type modifier that uses the variable type to indicate that it can be changed by unknown factors in some readers.

For example, operating system, hardware, or other program. When we encounter the variation of this keyword, the browser will ask about the variation.

The proxy service is no longer optimized, but can provide customized access questions for special addresses.

The following example shows how to use the Keyword:
Int volatile nvint;
When the volatile variable value is required, the system always retrieves data from its internal memory, that is

So that the preceding Command records the data obtained from the cursor. The retrieved data volume is saved immediately.

For example:
Volatile int I = 10;
Int A = I;
...
// Other proxies do not explicitly inform the receiver about the I operation.

Int B = I;
Volatile indicates that I may change when I is used. each time you use it, it must be retrieved from the address of I.

The Token Generation generated by the attacker will retrieve the data from the I address again and put it in B. The regionalization method is that because the browser discovers

The generation of the I dataset does not perform operations on I. It automatically places the last dataset in B. Instead of restarting

From the I region. In this case, if I is a register variable or indicates a port number, it is easy to export, so vola

Tile can be used to determine the issue for a special address.
Note: In vc6, the general messaging mode has not been replaced, so the function of this word cannot be seen. Lower limit

By inserting the primary keys on behalf of Alibaba, the primary keys have no volatile keywords, which are the most representative of the program:
First, use classwizard to create a Win32 console project, insert a voltest. cpp file, and then import the following

Generation:
 
# Include <stdio. h>
Void main ()
{
Int I = 10;
Int A = I;
 
Printf ("I = % d/N", );
// The Role Of The following sentence is to change the I value in the memory, but it is not known to the memory generator.
_ ASM {
MoV dword ptr [ebp-4], 20 h
}
 
Int B = I;
Printf ("I = % d/N", B );
}
Then, run the program in zookeeper version. The result is as follows:
I = 10
I = 32
Then, run the program in the release version mode, and the results are as follows:
I = 10
I = 10
The final result of explain indicates that, in the release mode, the release generator performs optimized on the generation, and the second time there is no correct I value.

Next, we will add the volatile keyword of I to see how it changes:
# Include <stdio. h>
Void main ()
{
Volatile int I = 10;
Int A = I;
 
Printf ("I = % d/N", );
_ ASM {
MoV dword ptr [ebp-4], 20 h
}
 
Int B = I;
Printf ("I = % d/N", B );
}
In other words, the runtime program in release and release versions is:
I = 10
I = 32
This tells us that this related word plays a role!

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.