static: In C, the static keyword has three distinct roles:
1). In the body of the function is declared as a static variable in the process of this function is called maintain its value unchanged.
2).
in the module (but in the function body), a variable is declared as static can be used within the function to access the module, but other functions can not be accessed outside the module. It is a local global variable.
3).
in the module, a function is declared as static can be the only other function calls within the module. That is, this function is limited to the module it is declared a local range.
Most of the candidate can correctly answer the first part, part correctly answer the second part, with very few people can understand is the third part. This is a candidate for serious drawback, because he obviously does not understand the scope of the localization data and the benefits and importance of the code.
============================================== ====< br />========================================< br />
Const:
1. keyword const role is to give people who read your code very useful information to convey, in fact, declare a parameter as a constant in order to tell the user this parameters of the application purpose.
2. by giving the optimizer some additional information, use the keyword const may be able to generate more compact code.
3. reasonable use of the const keyword allows the compiler to protect those who do not naturally want to be changed parameters, to prevent their inadvertent code changes. In short, thus reducing the bug to appear.
What is the meaning of const keyword?
I just heard the interviewee said: “const means constant”, Dan
Saks has been fully in his article summarizes all the usage of const, so the ESP (the translator : Embedded Systems
Programming) every reader should be very familiar with what const can do and can not do anything if you have not read the article, as long as say const means “read only” on it .
const int a;
int const a;
const int * a;
int * const a;
int const * a const;
the role of the first two are the same, a is a constant integer.
The third point means that A is a constant pointer to an integer (that is, integer can not be modified, but the pointer).
fourth means A is a constant pointer pointing to an integer (that is, integer pointer can be modified, but the pointer is not modified).
The last point means that A is a constant pointer to constant integer (that is, integer pointer is not modified, while the pointer is not modified).
========================================== ========< br />======================================
Volatile:
a volatile variable is defined as a variable may be said that this unexpected change, so the compiler will not go to assume a value of this variable. Accurate to say that, the optimizer uses this variable must be carefully re-read each time the value of this variable, rather than stored in the register in the backup. Here are a few examples of volatile variables:
1. Parallel device hardware registers (such as: the status register)
2. An interrupt service routine will have access to the non-automatic variables ( Non-automatic variables)
3. multi-threaded applications, shared by several task variables.
This is the distinction between C programmers and embedded systems programmers the most basic problems. Embedded systems programmers often associated with hardware, interrupts, RTOS, etc. to deal with, the use of these require volatile variables. Do not know how volatile content will lead to disaster.
assuming the interviewee is the correct answer to this question (ah, doubt whether this will be the case), I will get to the bottom a little bit, look at this guy is not straight is to understand the importance of completely volatile.
1). an argument may be a const can also be volatile it? Explain why.
2). a pointer can be volatile it? Explain why.
3). What is wrong with the following functions:
int square (volatile int * ptr)
{

return * ptr * * ptr;
}
Here is the answer:
1).
Yes. One example is read-only status register. It is volatile because it may be changed unexpectedly. It is const because the program should not attempt to modify it.
2). Yes. Although this is not very common. One example is when a service routine in the repair of a pointer to a buffer pointer.
3).
code are a hoax. The purpose of this code is used to return the pointer * ptr points to the value of the square, but because * ptr points to a volatile-type parameters, the compiler will generate code similar to:
int square (volatile int * ptr) < br />
{
int a, b;
a = * ptr;
b = * ptr;

return a * b;
}
* ptr value as may be unexpected to the change, so a and b may be different. Result, this code may not return to the square of the value you expect! Correct code is as follows:
long square (volatile int * ptr)
{
int a;
a = * ptr;
return a * a;
}
==================== ==============================< br />================ ==============================< br />
knowledge of C language