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
write a program to print largest number of each row of a 2D array
What is define c?
What is function prototype?
What is clrscr in c?
Explain what is the difference between the expression '++a' and 'a++'?
What is the role of this pointer?
Write a program to print fibonacci series without using recursion?
What is the difference between c and python?
How do I copy files?
1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. 2) the Event Manager has to send participants to the stage to perform in the order in which they registered. Write a program that will help the Event Manager know who to call to the stage to perform. The Logic should be in Data Structures
Explain what header files do I need in order to define the standard library functions I use?
what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?
what do you mean by inline function in C?
What is c definition?
Is it better to use a macro or a function?