Re: FW: (unknown)

"Victor R. Volkman" <[email protected]>
Newsgroups gmane.comp.programming.cppug
Message-ID <[email protected]>
That's not a good example.  Any function can have arbitrary side effects.
For example, your function which reads port data might update some
static variables.   This optimization would not actually be done by a
compiler.  Consider if you have a void function foo() called three times:

   foo();
   foo();
   foo();

You are telling me that this would be not be optimized whereas this
would?
   x = foo();
   x = foo();
   x = foo();

The examples I've seen with volatile always involved pointers.

At 10:40 PM 11/17/2003 +0800, you wrote:

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