←back to thread

1371 points yett | 1 comments | | HN request time: 0.213s | source
Show context
pmarreck ◴[] No.43774498[source]
My takeaway, speaking as someone who leans towards functional programming and immutability, is "this is yet another example of a mutability problem that could never happen in a functional context"

(so, for example, this bug would have never been created by Rust unless it was deeply misused)

replies(8): >>43774636 #>>43774657 #>>43774734 #>>43774921 #>>43775019 #>>43775231 #>>43775948 #>>43780177 #
grishka ◴[] No.43774636[source]
This is more of a problem of the C/C++ standard that it allows uninitialized variables but doesn't give them defined values, considering it "undefined behavior" to read from an uninitialized variable. Java, for example, doesn't have this particular problem because it does specify default values for variables.
replies(1): >>43777425 #
mabster ◴[] No.43777425[source]
But it's this and many other features of C/C++ that make it faster than Java. C/C++ developers really don't want to "pay" for something for safety.

Though, I really like the _mm_undefined_ps() intrinsics for SSE that make it clear that you're purposefully not initialising a variable. Something like that for ints and floats would be pretty sweet.

replies(3): >>43777808 #>>43778050 #>>43783802 #
1. Dylan16807 ◴[] No.43777808[source]
Statically proving the variables get initialized wouldn't change the performance except by making sure you check the return value of sscanf, or turning refusal to check into a couple register wipes. Either way, that's a negligible increase to a hefty function call. It wouldn't require default initializing variables in all circumstances.

When I think of the "no runtime cost" mentality of C/C++ I don't think that normally extends to ignoring errors in I/O functions.