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 client and server program in C language using UDP, where client program interact with the Server as given below: i) The client begins by sending a request to send a string of 8 characters or series of 7 numbers, the server sends back a characters or numbers as per the request of the client. ii) In case of series of 7 numbers: The client sends a multiplication of numbers, to the server. iii) In case of a string of 8 characters: The client sends a reverse order of string to the server.. iv) Server will send an acknowledgment to the client after receiving the correct answer
Explain the binary height balanced tree?
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
What is break statement?
What is the usage of the pointer in c?
What is operator precedence?
write a program fibonacci series and palindrome program in c
1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321
Why static variable is used in c?
What does s c mean in text?
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
What are the features of c languages?
Is there any demerits of using pointer?
What is c++ used for today?
What are the types of variables in c?