How does Volatile const variable differs from const variable for
following queries.
1. If declare variable with type qualifier Volatile
const where it will be stored ?
eg:
extern const volatile unsigned long int rt_clk; (not a pointer)
Where will be The variable rt_clk get stored either in ROM or
RAM ?
If the Ans is ROM the value inside variable never be changed at any
caust isnt it?
If the Ans is RAM still its const why it get stored in RAM ?
(Please guide me with variable not with pointer for the first
question)
2. What is the differents bettween Volatile const *
and const * ?
of coures my question focus on address only. Not value inside the
address which hold by the pointer ?
eg:-
unsigned char *const prt1 = &ch;
const volatile unsigned char * prt2;
what is differents between prt1 and prt2 ?
> Hi,
First, you are asking your question in the wrong group. comp.std.c is
for questions about the past, present, and future of the International
Standard that defines the C language, not about actually programming
in the language.
> How does Volatile const variable differs from const variable for
> following queries.
There is no such thing as "Volatile" in the C language, there is a
keyword volatile. Note the difference, C is a case-sensitive
language.
Also, the concept of a variable does not necessarily map well to the C
language, particularly not in conjunction with the use of the const
keyword. A program is not permitted to modify something defined with
the const qualifier, so it is not really "variable" in that sense.
> 1. If declare variable with type qualifier Volatile
> const where it will be stored ?
>
> eg:
>
> extern const volatile unsigned long int rt_clk; (not a pointer)
A declaration that is not also a definition does not allocate storage
for anything. The extern keyword tells the compiler that it may refer
to this object (not variable), and the object will be supplied when
the program is executed. It says nothing at all about where the
object will be.
> Where will be The variable rt_clk get stored either in ROM or
> RAM ?
C does not define or recognize "ROM" or "RAM", just memory. Where the
object will reside in the final program does not depend on the file
that contains an external declaration for it. It depends on how it is
defined, not just declared. And it possibly depends on implementation
specific use of tools such as a linker and locater that are part of
the tool chain.
> If the Ans is ROM the value inside variable never be changed at any
> caust isnt it?
The answer, which is what I think you mean by "Ans" is not ROM or RAM,
but wherever the implementation decides to store it.
> If the Ans is RAM still its const why it get stored in RAM ?
>
> (Please guide me with variable not with pointer for the first
> question)
Again, a const object is not something that can be called a variable
from the normal use of that term.
> 2. What is the differents bettween Volatile const *
> and const * ?
>
> of coures my question focus on address only. Not value inside the
> address which hold by the pointer ?
The first points to an object that may change unpredictably, and may
not be modified through that pointer. The second is a pointer to an
object that may be read, but not written, through that pointer.
> eg:-
>
> unsigned char *const prt1 = &ch;
>
> const volatile unsigned char * prt2;
>
> what is differents between prt1 and prt2 ?
I just explained that above.
In the future, questions of this type belong in comp.lang.c, not here.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jack Klein,
Thank you so mach , Even the question belongs not to this group you
made reply.
Thanks once again.
but still i am not confussed because , If we decleare any variable
are constant
the linker will decide where that variable or constant should have
the space eithere in
ROM or RAM I believe , provided if its not dinamic memory
allocation .
As per the delcaration below . were will be the memeory space
allocated either ROM or RAM after linking
unsigned long int const volatile rt_clk;
ok fine I ll proceed with comp.lang.c group thanks for your
guidence.
Regards
gopalan
It seems to me you are confused.
Volatile qualification means that all read and write accesses
will occur according to the abstract C machine model; i.e.
no caching of a storage object in registers is allowed.
Const qualification means that only read access is allowed.
One may meaningfully specify both qualifications.
Douglas A. Gwyn wrote:
> It seems to me you are confused.
> Volatile qualification means that all read and write accesses
> will occur according to the abstract C machine model; i.e.
> no caching of a storage object in registers is allowed.
> Const qualification means that only read access is allowed.
> One may meaningfully specify both qualifications.
Simply put, a const volatile variable is a read-only object in
memory, meaning that it cannot be modified (assigned to),
and the compiler is obliged to make all uses of the variable's
value actual reads of the variable (i.e., multiple uses of
its value cannot be optimized away, and each use must read
the value of the object).
Real-world examples include variables that are shared between
the program and some external data source, such as a read-only
hardware port or register mapped into a variable, whose value
may change outside the control of the program that reads its
value. Another example is some kind of special flag or status
variable in a library shared between multiple executing threads,
and whose value is modified by the operating system under
special conditions.
-drt