Message Font: Serif | Sans-Serif
 
UnThreaded | Threaded | Whole Thread (17) | Ignore Thread Prev Thread | Prev | Next | Next Thread
Author: rmhj Big gold star, 5000 posts Old School Fool Add to my Favorite Fools Ignore this person (you won't see their posts anymore) Number: of 5814  
Subject: Re: A (complex) puzzle Date: 9/27/2011 11:15 AM
Post New | Post Reply | Reply Later | Create Poll . Report this Post | Recommend it!
Recommendations: 1
rev2217/norm: The standards of most programming languages, including Fortran and C/C++, explicitly forbid optimizations that fail to preserve the integrity of parentheses in order to give programmers control of the sequence of operations when it matters. Thus, such an optimization is illegal.

This is (or was) part of the FORTRAN (IV) standard; I can't say about newer FORTRANs, though I doubt it has changed. It is *not* part of the C standard, and never has been. C guarantees ordering of statements separated by &&, ||, ^^, and a few others, but guarantees nothing about optimization. From Harbison & Steele, Fifth Edition, Section 7.3.3, "Parenthesized Expressions": "Parentheses do not necessarily force a particular evaluation order.... The purpose of the parenthesized expression is simply to delimit the enclosed expression for grouping purposes, either to defeat the default precedence of operators or make the code more readable."

That said, I doubt that many C optimizers would apply this identity to optimize this expression.

rj
Post New | Post Reply | Reply Later | Create Poll . Report this Post | Recommend it!
Print the post  
UnThreaded | Threaded | Whole Thread (17) | Ignore Thread Prev Thread | Prev | Next | Next Thread

Announcements

2013 Feste Award Voting Begins!
Who will win the 2013 Feste Award? Vote now for the Fool that most exemplifies the Fool Community mission of Learning Together!
When Life Gives You Lemons
We all have had hardships and made poor decisions. The important thing is how we respond and grow. Read the story of a Fool who started from nothing, and looks to gain everything.
Post of the Day:
Berkshire Hathaway

Reestablishing the Middle Class
What was Your Dumbest Investment?
Share it with us -- and learn from others' stories of flubs.
Community Home
Speak Your Mind, Start Your Blog, Rate Your Stocks

Community Team Fools - who are those TMF's?
Contact Us
Contact Customer Service and other Fool departments here.
Work for Fools?
Winner of the Washingtonian great places to work, and "#1 Media Company to Work For" (BusinessInsider 2011)! Have access to all of TMF's online and email products for FREE, and be paid for your contributions to TMF! Click the link and start your Fool career.
Advertisement