Let's take a look at the basic things that have not been mastered. I'm glad to have such a leisurely time. You can learn the C language again.
<1> const char * variable. A pointer to a constant can point to a constant, but it cannot be used to change the value of the indicated object.
<2> # The symbols defined in define are replaced directly.
<3> the content of the volatile variable is described inProgramChanges at any time when unknown.
The volatile variable is variable, allowing users to modify other content than programs, such as hardware.
Access to the data will directly access the content of the address at any time, that is, the optimization of the access speed through the cache is canceled.
For example, if the terminal of the hardware device changes it, the hardware device usually has its own private memory address, such as the video memory.
Generally, they are reflected in a specific memory address through an image.
In this way, under some conditions, the program can directly access these private memory.
In addition, for example, when multiple programs operate on the shared memory address
Your program does not know when the memory will be changed
Without the volatile modification, the program uses the data in the cache, which may be outdated.
With the volatile modifier, the program re-extracts the address when needed to ensure that it is up to date.
For example, transfer the address of the global variable to the clock subroutine of the operating system, and use the global variable to save the real-time clock value of the system.