Created
December 30, 2014 12:43
-
-
Save airspeedswift/9abca0419f5c337a5b41 to your computer and use it in GitHub Desktop.
Different calculation results between -Onone and -O with inout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import Foundation | |
struct S { | |
var i: Int | |
} | |
func f(inout s: S) -> Int { | |
s.i += 1 | |
return s.i | |
} | |
var s = S(i: 0) | |
// let d = NSDate() | |
let r1 = f(&s) | |
let r2 = f(&s) | |
println("r1 = \(r1), r2 = \(r2)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Incidentally, uncommenting that NSDate line makes the problem go away...