Chetan Sakhardande wrote:

> Could anyone explain the following:
> 
> What do the extern and volatile keywords mean if applied to 
> a) a variable
> b) a function
> 
> What is a static function and what is its use?

`extern' means that the variable or function will be defined in
another file. The purpose of an extern declaration is so that the
compiler can type-check any references to the symbol.

`volatile' means that the variable can be modified in unexpected ways
(e.g. from within a signal handler, by hardware, or by another
thread). It prevents the compiler from performing certain
optimisations which won't work (specifically, it won't keep a copy of
the variable in a register). It can't meaningfully be applied to
functions.

`static' has two uses.

When applied to functions or global variables, it indicates that the
symbol will only be referenced from within that source file. The
compiler doesn't export `static' symbols, so you cannot reference them
from another file.

When applied to local variables, it indicates that the variable has a
specific location in memory (in the program's data segment), rather
than being stored on the stack (which is the default). The main
consequence of this is that the variable's value is retained between
successive invocations of the function.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to