freelanceprogrammers.org Forum Index » C
doubt on volatile data type
Joined: 28 Dec 2004
Posts: 3
doubt on volatile data type
Hi all,
what is volatile data type mean???
why?? when it used??
can a varible be declared as both volatile & const
type?
(const volatile int i;)
Rgds
Madhuar
________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
Joined: 02 Jan 2005
Posts: 9
doubt on volatile data type
--- Madhukar mythri <madhukar_linux@...>
wrote:
>
> Hi all,
> what is volatile data type mean???
> why?? when it used??
>
> can a varible be declared as both volatile & const
> type?
> (const volatile int i;)
>
>
> Rgds
> Madhuar
Hi Madhur,
A volatile data type is usually a type which is shared
between two threads of a process. We need to specify
them volatile to the compiler so that whenever the
compiler needs to access it, it accesses it from the
original location of the memory and not from the
cache, as it might be changed by the other thread.
With Regards
Manik
>
>
________________________________________________________________________
> Yahoo! India Matrimony: Find your life partner
> online
> Go to: http://yahoo.shaadi.com/india-matrimony
>
>
>
>
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail
Joined: 29 Dec 2004
Posts: 31
doubt on volatile data type
From: Madhukar mythri [mailto:madhukar_linux@...]
>Hi all,
> what is volatile data type mean???
It tells the compiler that it cannot assume that the value of the
variable will stay the same between two consecutive reads. For example
in the following code, the compiler may assume j will not change:
int j
for(j=0; j<10; j++){
/* code that does NOT modify j */
}
>why?? when it used??
When something external to the code under consideration may modify the
variable. Examples include another thread in the same program, or the
variable may be mapped to external I/O.
>can a varible be declared as both volatile & const
>type?
>(const volatile int i;)
Yes. If (for example) it is a `read only`, for example I/O Mapped serial
comms in. There would be no point in allowing the programmer to write to
this point.
--
PJH
"...one of the main causes of the fall of the Roman Empire was that,
lacking zero, they had no way to indicate successful termination of
their C programs." - Robert Firth
Alderley plc, Arnolds Field Estate, The Downs, Wickwar, Gloucestershire, GL12
8JD, UK
Tel: +44(0)1454 294556 Fax: +44 (0)1454 299272
Website : www.alderley.com Sales : sales@... Service :
service@...
This email and its contents are confidential and are solely for the use of the
intended recipient. If you are not the original recipient you have received it
in error and any use, dissemination, forwarding, printing or copying of this
email is strictly prohibited. Should you receive this email in error please
immediately notify it@...
This email has been scanned for viruses, however you should always scan emails
with your own systems prior to opening.
Joined: 25 Jul 2003
Posts: 48
doubt on volatile data type
Reply embedded...
> -----Original Message-----
> From: Madhukar mythri [mailto:madhukar_linux@...]
> Sent: Wednesday, January 05, 2005 2:04 AM
> To: Programmers-Town@yahoogroups.com
> Subject: (PT) doubt on volatile data type
>
>
>
> Hi all,
> what is volatile data type mean???
The object can be modified outside the control and knowledge of your code,
or unknown side effects.
> why??
Because it is not "stable".
> when it used??
When you need to access object with volatile properties. It tells the
compiler not to assume that the value stays between read.
> can a varible be declared as both volatile & const
> type?
> (const volatile int i;)
Yes. They are not oxymoron.
`const` means you will not change it within your code, i.e. read-only.
`volatile` means it is changed by means outside the control of your program,
so compiler should always read the current value of the object instead of
assume it never changed.
HTH
Shyan
Joined: 28 Dec 2004
Posts: 3
doubt on volatile data type
Hi ,
Thanks for reply...
Rgds
Madhukar
________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







