Recommended Answers
Jump to PostWhether this is good pracrice or not is not the question I asked. The mystery is why the two compilers (from one company, no less) give different results. What is this telling us?
Absolutely nothing -- since it is undefined behavior.
Jump to Post>So where is the error in my analysis?
The part where you relied on undefined behavior to do something predictable. I can't figure out if you're really as dense as you seem, or just stubborn.I understand you now. I took "undefined behavior" to mean the computation will return an …
Jump to PostI think this will fix it: replace y = x+1 by eiither y = double(x)+1 or y = 1.0*x + 1 or even y = x + 1.0
No, trading one UB for another doesn't fix it.
Jump to PostNo, trading one UB for another doesn't fix it.
K&R has a section on type conversions (Section 2.7). It seems to me that the stuff I've done is ok. Where is the UB?
Jump to PostK&R has a section on type conversions (Section 2.7). It seems to me that the stuff I've done is ok. Where is the UB?
Conversion of a double to an int when the value is outside the range of an int.
6.3.1.4 Real floating and integer
1 …
All 34 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.