use of volatile ?

  • Thread starter parasprajapati2001
  • Start date
C

Chris Dollin

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?
 
M

Matthew Hicks

One case is for the variables only accessed inside an interrupt service routine.


---Matthew Hicks
 
A

Army1987

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.
 
S

satish

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.....
 
K

Keith Thompson

satish said:
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.
 
C

CBFalconer

satish said:
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.
 
R

Richard Heathfield

CBFalconer said:
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.
 
C

Christopher Benson-Manica

Richard Heathfield said:
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...
 
R

Richard Bos

Christopher Benson-Manica said:
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
 
J

Joe Wright

Richard said:
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.
 
F

Flash Gordon

Clever Monkey wrote, On 03/07/07 15:14:
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.
 
C

Chris Dollin

Richard said:
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?
 
K

Keith Thompson

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?
 
A

Army1987

Joe Wright said:
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?)
 
K

Keith Thompson

Army1987 said:
Joe Wright said:
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".
 
C

CBFalconer

Joe said:
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 :)
 
A

Army1987

Keith Thompson said:
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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

The Semantics of 'volatile' 73
Qsort() messing with my entire Code 0
Proper Use of Volatile? 6
volatile Info 56
volatile 4
Volatile and code reordering 1
volatile and multiple threads 10
Volatile? 3

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top