static
means a variable will be globally known only in this file. extern
means
a global variable defined in another file will also be known in this
file, and is also used for accessing functions defined in other files.
Please any one explain me about
1. Global variable (example : int i_Global)2. Extern variable (example : extern int i_Global)
3. static variable (example : static int i_Local means in .h file)
4. static global variable ( example : static int i_Global)
http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/15b55a9f-ee92-495a-a18c-9f5dc42cca96
http://stackoverflow.com/questions/3684450/what-is-the-difference-between-static-and-extern-in-c
storage
- Local variables and function frame - stack
- Global and static variables if uninitialized - .bss block start by symbol
- Global and static variables if initialized - data segment
- Environment variables and arguments - on top of the stack
- Dynamic data allocation - heap
- Const - ROM
- Volatile - no storage
- Register - cpu register
- Const volatile - in the same place as const storage
In which section is constant volatile variable stored in c.?
In micro-controllers we should put such kind of variables in RAM. Right?
|
||||
A
const volatile variable
means that your C program can't legally change it, but something else
can. It would be logical to place this variable in RAM, but the compiler
won't complain if you tell it (via a linker script or a similar option)
to place in ROM. It may also be useful to locate this variable where
some memory-mapped device is, e.g. a read-only timer counter register or
an ADC output register. |
|||||
|
Volatile has noting to do with where the variable is stored. It just tells the compiler to read the variable from memory every time to avoid any optimization that compiler might perform for that variable. |
|||
const variables for microcontroller applications are most likely stored in flash ROM.
The only time they are stored in RAM is when they are evaluated in
runtime, such as const parameters to functions. Or when you are doing
some debug build executing from RAM.volatile has nothing to do with where variables are stored, as explained in other answers. |
Difference between const & const volatile
http://stackoverflow.com/questions/4592762/difference-between-const-const-volatile
If we declare a variable as
volatile every time the fresh value is updatedIf we declare a variable as const then the value of that variable will not be changed Then const volatile int temp; What is the of declaring the variable temp as above? What happens if we declare as const int temp ? | |||||||
3 Answers
|
An object marked as
const volatile will not be permitted to be changed by the code (an error will be raised due to the const qualifier) - at least through that particular name/pointer.The volatile part of the qualifier means that the compiler cannot optimize or reorder access to the object.In an embedded system, this is typically used to access hardware registers that can be read and are updated by the hardware, but make no sense to write to (or might be an error to write to). An example might be the status register for a serial port. Various bits will indicate if a character is waiting to be read or if the transmit register is ready to accept a new character (ie., - it's empty). Each read of this status register could result in a different value depending on what else has occurred in the serial port hardware. It makes no sense to write to the status register (depending on the particular hardware spec), but you need to make sure that each read of the register results in an actual read of the hardware - using a cached value from a previous read won't tell you about changes in the hardware state. A quick example:
If these pointers were not marked as being volatile , a couple problems might occur:
volatile qualifiers ensures that these optimizations are not performed by the compiler. |
||||
|
|
It is not because the variable is const that it may not have changed between two sequence points.
Constness is a promise you make not to change the value, not that the value won't be changed. |