next up previous contents index
Next: Unions and bitfields (advanced) Up: Types Previous: Function pointers (advanced)   Contents   Index


Type qualifiers (advanced)

Any variable declaration can be prefixed with a type qualifier: const or volatile. We will only describe const here and refer the user to a more complete reference for a description of volatile.

const is used as a `hint' to the compiler that the variable will not be changed any point within the scope of the declaration. This may allow the compiler to generate code optimized more efficiently, and it will certainly warn you if you modify the variable accidentally.

  
void f(void) {
  const int i=10;  /*  we will not modify i  */
  /* .. */
}
A more common use is in conjunction with pointer arguments to a function:

  
void display(const char* message) {  /*  the function guarantees 
                                         not to modify message  */
  /* .. */
}



CATAM admin 2010-02-23