473,473 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

use of volatile ?

can any one give an example which use volatile keyword ?

Jul 2 '07 #1
20 1789
pa****************@gmail.com wrote:
can any one give an example which use volatile keyword ?
Voila:

#include <signal.h>

volatile sig_atomic_t bromine;

What did you really want to know, and why?

--
Chris "small steps" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Jul 2 '07 #2
One case is for the variables only accessed inside an interrupt service routine.
---Matthew Hicks

can any one give an example which use volatile keyword ?

Jul 2 '07 #3

<pa****************@gmail.comha scritto nel messaggio news:11**********************@i38g2000prf.googlegr oups.com...
can any one give an example which use volatile keyword ?
It serves to declare a variable which could change behind the
program's back, so the program must access it whenever the abstract
machine does.

For example:
#include <time.h>
double measure_time(int (*func)(int), int min, int max)
{
clock_t t0, t1;
volatile int res;
int i;
double el0, el1;
t0 = clock();
for (i = min; i <= max; i++)
res = func(i);
t1 = clock();
el0 = (t0 - t1) / ((double)max - min + 1) / CLOCKS_PER_SEC;
t0 = clock();
for (i = min; i <= max; i++)
res = 0;
t1 = clock();
el1 = (t0 - t1) / ((double)max - min + 1) / CLOCKS_PER_SEC;
return el0 - el1;
/* the time needed for the first loop including function calls,
* minus the time needed for the loop itself */
}

If res weren't volatile, and func() had no side effect, the
compiler would be free to optimize away all the calls to func()
except the last one, as they would be useless and no strictly
conforming program could determine that they weren't actually
executed.
Jul 2 '07 #4
i will give u an example...

void getio()
{
char *ioport=0x7777;
volatile char ch=ioport; /* read first byte of data*/
ch=ioport; /* read second byte of data*/
}
if u declare datatype as volatile the compiler optimization will not
remove the
redundant expressions as above.....

Jul 2 '07 #5
satish <sa*******@gmail.comwrites:
i will give u an example...

void getio()
{
char *ioport=0x7777;
volatile char ch=ioport; /* read first byte of data*/
ch=ioport; /* read second byte of data*/
}
if u declare datatype as volatile the compiler optimization will not
remove the
redundant expressions as above.....
You should try compiling any code before you post it here.

char *ioport=0x7777;
attempts to initialize a pointer with an integer. There is no
implicit conversion from pointer types to integer types (except for
the special case of a null pointer constant). This is a constraint
violation, requiring a diagnostic from the compiler (though some
compilers may accept it anyway).

volatile char ch=ioport;
Here you initalize a char object with a pointer value. See above.

ch=ioport;
And again.

Also, please don't use silly abbreviations like "u". This isn't a
chat room.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 2 '07 #6
satish wrote:
>
i will give u an example...
Who are i and u? If i is supposed to reference you, it is spelled
'I'. 'u' is totally unknown, even 'U' has not posted here for at
least a year.

In other words, don't use geek speek in Usenet.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jul 3 '07 #7
CBFalconer said:
satish wrote:
>>
i will give u an example...

Who are i and u? If i is supposed to reference you, it is spelled
'I'. 'u' is totally unknown, even 'U' has not posted here for at
least a year.

In other words, don't use geek speek in Usenet.
I always wondered what a geek was. Now I know - it's someone who can't
type.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 3 '07 #8
Richard Heathfield <rj*@see.sig.invalidwrote:
I always wondered what a geek was. Now I know - it's someone who can't
type.
Whew, that lays to rest my long-standing fears that I was one. Now I
can go rejoin society...

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Jul 3 '07 #9
Richard Heathfield wrote:
CBFalconer said:
>satish wrote:
>>i will give u an example...
Who are i and u? If i is supposed to reference you, it is spelled
'I'. 'u' is totally unknown, even 'U' has not posted here for at
least a year.

In other words, don't use geek speek in Usenet.

I always wondered what a geek was. Now I know - it's someone who can't
type.
Not according to the canonical definition:
<http://catandgirl.com/view.php?loc=94>
--
clvrmnky <mailto:sp******@clevermonkey.org>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
Jul 3 '07 #10
Christopher Benson-Manica <at***@otaku.freeshell.orgwrote:
Richard Heathfield <rj*@see.sig.invalidwrote:
I always wondered what a geek was. Now I know - it's someone who can't
type.

Whew, that lays to rest my long-standing fears that I was one. Now I
can go rejoin society...
Answer this question quickly, and don't think about it beforehand:

How many syllables are there in the word "coax"?

Richard
Jul 3 '07 #11
Richard Bos wrote:
Christopher Benson-Manica <at***@otaku.freeshell.orgwrote:
>Richard Heathfield <rj*@see.sig.invalidwrote:
>>I always wondered what a geek was. Now I know - it's someone who can't
type.
Whew, that lays to rest my long-standing fears that I was one. Now I
can go rejoin society...

Answer this question quickly, and don't think about it beforehand:

How many syllables are there in the word "coax"?

Richard
That's good. If you answer 'two' you're a geek.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Jul 3 '07 #12
Clever Monkey wrote, On 03/07/07 15:14:
Richard Heathfield wrote:
>CBFalconer said:
>>satish wrote:
i will give u an example...
Who are i and u? If i is supposed to reference you, it is spelled
'I'. 'u' is totally unknown, even 'U' has not posted here for at
least a year.

In other words, don't use geek speek in Usenet.

I always wondered what a geek was. Now I know - it's someone who can't
type.
Not according to the canonical definition:
<http://catandgirl.com/view.php?loc=94>
Based on that and my salary I am a nerd rather than a geek. However, my
definitions of the difference would be more that a geek knows and
accepts what s/he is, a nerd does not. Or, "the difference between a
geek and a nerd is that a geek knows the difference between a geek and a
nerd." Also nerd still tends to be considered an insult whereas geek
tends to be more a statement of what one is.
--
Flash Gordon
Definitely either a geek or a nerd, which depends on your definition.
Jul 3 '07 #13
Richard Bos wrote:
Christopher Benson-Manica <at***@otaku.freeshell.orgwrote:
>Richard Heathfield <rj*@see.sig.invalidwrote:
I always wondered what a geek was. Now I know - it's someone who can't
type.

Whew, that lays to rest my long-standing fears that I was one. Now I
can go rejoin society...

Answer this question quickly, and don't think about it beforehand:

How many syllables are there in the word "coax"?
Why should I answer such an ambiguous question?

--
Singularly Plural Hedgehog
"A facility for quotation covers the absence of original thought." /Gaudy Night/

Jul 3 '07 #14
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Christopher Benson-Manica <at***@otaku.freeshell.orgwrote:
>Richard Heathfield <rj*@see.sig.invalidwrote:
I always wondered what a geek was. Now I know - it's someone who can't
type.

Whew, that lays to rest my long-standing fears that I was one. Now I
can go rejoin society...

Answer this question quickly, and don't think about it beforehand:

How many syllables are there in the word "coax"?
Two, of course, but isn't it usually spelled with a 'k' and preceded
by Brekekekex?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 3 '07 #15

"Joe Wright" <jo********@comcast.netha scritto nel messaggio news:hJ******************************@comcast.com. ..
Richard Bos wrote:
>Christopher Benson-Manica <at***@otaku.freeshell.orgwrote:
>>Richard Heathfield <rj*@see.sig.invalidwrote:

I always wondered what a geek was. Now I know - it's someone who can't type.
Whew, that lays to rest my long-standing fears that I was one. Now I
can go rejoin society...

Answer this question quickly, and don't think about it beforehand:

How many syllables are there in the word "coax"?

Richard

That's good. If you answer 'two' you're a geek.
Hey, I'm a geek!
(Actually, I'm not a native English speaker, and I hadn't heard of that word before. I thought it was pronounced with two syllable
because of what I guessed it meant. A Wikipedia search shown that
my guess was right, but why should a non-geek pronounce it as one
syllable?)
Jul 3 '07 #16
Army1987 <pl********@for.itwrote:
How many syllables are there in the word "coax"?
why should a non-geek pronounce it as one syllable?
Because the one syllable word has a non-geek meaning.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Jul 3 '07 #17
"Army1987" <pl********@for.itwrites:
"Joe Wright" <jo********@comcast.netha scritto nel messaggio
news:hJ******************************@comcast.com. ..
>Richard Bos wrote:
[...]
>>Answer this question quickly, and don't think about it beforehand:

How many syllables are there in the word "coax"?
That's good. If you answer 'two' you're a geek.
Hey, I'm a geek! (Actually, I'm not a native English speaker, and I
hadn't heard of that word before. I thought it was pronounced with
two syllable because of what I guessed it meant. A Wikipedia search
shown that my guess was right, but why should a non-geek pronounce
it as one syllable?)
To a geek, "coax" is short for "coaxial", as in "coaxial cable".

To a non-geek, it's an ordinary non-technical word meaning "to attempt
to influence by gentle persuasion, flattery, etc.; cajole", pronounced
as one syllable with a long 'o'. See
<http://dictionary.reference.com/browse/coax>.

I tried to use Babelfish to get an Italian translation, but it
translates "coax" as "coassiale", which it translates back to English
as "coaxial". (Apparently the folks who implemented Babelfish are
geeks; who would have guessed?) But it translates "coaxing" as
"persuadere con le lusinghe", which re-translates to "to persuade with
flatteries".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 3 '07 #18
Joe Wright wrote:
Richard Bos wrote:
>Christopher Benson-Manica <at***@otaku.freeshell.orgwrote:
>>Richard Heathfield <rj*@see.sig.invalidwrote:

I always wondered what a geek was. Now I know - it's someone
who can't type.

Whew, that lays to rest my long-standing fears that I was one.
Now I can go rejoin society...

Answer this question quickly, and don't think about it beforehand:

How many syllables are there in the word "coax"?

That's good. If you answer 'two' you're a geek.
I think there are very few participants here who even considered
the one syllable version. We don't coax, we ramrod :-)

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jul 3 '07 #19

"Keith Thompson" <ks***@mib.orgha scritto nel messaggio news:ln************@nuthaus.mib.org...
To a geek, "coax" is short for "coaxial", as in "coaxial cable".

To a non-geek, it's an ordinary non-technical word meaning "to attempt
to influence by gentle persuasion, flattery, etc.; cajole", pronounced
as one syllable with a long 'o'. See
<http://dictionary.reference.com/browse/coax>.

I tried to use Babelfish to get an Italian translation, but it
translates "coax" as "coassiale", which it translates back to English
That's why I guessed the way I did...
as "coaxial". (Apparently the folks who implemented Babelfish are
geeks; who would have guessed?) But it translates "coaxing" as
"persuadere con le lusinghe", which re-translates to "to persuade with
flatteries".
There are far more common ways to say that in Italian, even with a
single verb. (I've never used Babelfish, except once to get to
understand a japanese text. It didn't translate it into *real*
English, but at least was understandable.)
Jul 4 '07 #20
Keith Thompson <ks***@mib.orgwrote:
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Christopher Benson-Manica <at***@otaku.freeshell.orgwrote:
Richard Heathfield <rj*@see.sig.invalidwrote:
I always wondered what a geek was. Now I know - it's someone who can't
type.

Whew, that lays to rest my long-standing fears that I was one. Now I
can go rejoin society...
Answer this question quickly, and don't think about it beforehand:

How many syllables are there in the word "coax"?

Two, of course, but isn't it usually spelled with a 'k' and preceded
by Brekekekex?
Have you been lurking in the Shedde?

Richard
Jul 5 '07 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: newsock | last post by:
Why need to qualify a member function "volatile"? Why need to qualify a object "volatile"? When need to "const_cast" away "volatile" of an object and a member function? I also saw some code...
8
by: Tim Rentsch | last post by:
Here's another question related to 'volatile'. Consider the following: int x; void foo(){ int y; y = (volatile int) x;
5
by: ben | last post by:
Hello All, I am trying to make sense of a bit of syntax, is there a guru out there that can clear this up for me. I have a buffer declared as static volatile u8 buffer; and I have a...
14
by: Ian Pilcher | last post by:
It's pretty common to see declarations such as: static volatile sig_atomic_t caught_signal = 0; C99 defines sig_atomic_t as a "... (possibly volatile-qualified) integer type of an object that...
14
by: google-newsgroups | last post by:
Hello, even (or because?) reading the standard (ISO/IEC 9899/1999) I do not understand some issues with volatile. The background is embedded programming where data is exchanged between main...
17
by: dingoatemydonut | last post by:
The C99 standard states: "In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce...
18
by: Mark | last post by:
Hi List, I want to write a function to copy some data out of a hardware buffer. The hardware can change the contents of this buffer without it being written to by my function. I want to use...
94
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
3
by: Rakesh Kumar | last post by:
Hi - I am actually trying to get my feet in multi-threaded C++ programming. While I am aware that the C++ standard does not talk about threads (at least, for now - in C++03) - my question is more...
10
by: S James S Stapleton | last post by:
Is volatile necessary anymore? I have a two-thread piece of code I've been testing to figure out what volatile does (fairly simple code, uses pthreads). I have an update thread (variables passed as...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.