what is difference b/w extern & volatile variable??
Answer Posted / antonio leite
extern states that a variable is referenced in a module but
is declared in another module. This makes the linker not
generate an error/warning when the extern variable is
referenced but wait till the declaration is stated in a
module.
volatile states that the value of a variable can be changed
anywhere in the code. This is used by the optimizer to know
that a piece of code must not be optimized when a volatile
variable is found. For example, when a variable is changed
by a interrupt timer it must be declared volatile. The code
seems to be always true because Timer_xpto seems to be
always > 0. If the code is optimized, the if would simply
disapper from the code, but this is not what the programmer
wants, so declare
extern volatile unsigned long Timer_xpto;
so that the compiler will never optimize the code below.
Timer_xpto = 100;
do something
if (Timer_xpto > 0 )
{
do any other thing
}
Here extern is stating that the variable is declared in
other module and volatile that the code where the
Timer_xpto appears must not be optimized.
See http://www.eetimes.com/discussion/programming-
pointers/4025609/Place-volatile-accurately
| Is This Answer Correct ? | 13 Yes | 0 No |
Post New Answer View All Answers
What are the similarities between c and c++?
Explain about C function prototype?
What is multidimensional arrays
Is there any demerits of using pointer?
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }
can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......
When we use void main and int main?
Why is c called c not d or e?
Do character constants represent numerical values?
What are the Advantages of using macro
How do we print only part of a string in c?
List a few unconditional control statement in c.
What happens if a header file is included twice?
What are the types of assignment statements?