FW: (unknown)

"DUTTA, SAIKAT" <[email protected]>
Newsgroups gmane.comp.programming.cppug
Message-ID <ED1E7EFC7542454F9921F4A342E0189105A1B985@sgpexc02.asiapacific.cpqcorp.net>
Hi,

I'll try to give an example that I had read long time back. Suppose I
have the following:

int x = get 2 bytes from some port;
x = get next 2 bytes from same port;

Now in the above situation, since the port is same, compiler will assume
the the 2 statements to be identical and optimise by deleting the second
line, thinking it to be a repeat of the first.

This is unacceptable obviously. Thus if the variable 'x' was marked as
volatile, such optimizations won't be performed and the 2 lines remain
intact.

Hope this helps :)

Regards,

Saikat

------

Life is 10 percent what you MAKE it and 90 percent how you TAKE it!

------

Software Engineer            /                 Phone : +91 80 205 3854
HP ISO Pvt. Ltd.             /__   ___       Mobile: +91 9845441372
Al-Kareem                    /    / /__ /       E-mail:
[email protected]
2nd. Floor, Seat 38             /
Bangalore                    i n v e n t
 


-----Original Message-----
From: Viking >:) [mailto:[email protected]] 
Sent: Monday, November 17, 2003 2:40 PM
To: [email protected]
Subject: [cppug] (unknown)


Hello Group,

I am a new member to this group. 

Can any one please explain me about the volatile keyword.  According 
Mr.StrousStrup in "The C++ Programming Language"  the definition is 
as follows.

"A Volatile specifier is a hint to the Compiler that an object my 
change its value in ways not specified by the language, so aggressive 
optimizations to be avoided."


My doubts are 

"an object my change its value in ways not specified by the language"

1) What is this ? How will an object change  its ways in ways not 
specified by the language ? 

If some example is given about this , that would be greatful.

"so aggressive optimizations to be avoided."

2) Who does optimizations ? Compiler ? Does it does it automatically 
or by Specifing some switches...?


Thanks in Advance.

Cheers,
Blue Viking





To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/ 





------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/EbFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.