| ▲ | p1necone 3 hours ago | ||||||||||||||||
Just requiring explicit assignment before first use feels like the superior approach to automatic initialization, regardless of whether the automatic initialization is with 0 or with NaN. | |||||||||||||||||
| ▲ | WalterBright 3 hours ago | parent | next [-] | ||||||||||||||||
That suggestion is often made. The trouble with it is a bug I've seen often. People will get an error message about an "uninitialized variable". Then they go into "just get the compiler to shut up" mode, amd pick "0" as the initializer. Then, the program compiles and runs, and silently produces the wrong answer. Code reviews will simply pass over the "0" initializer, as it looks right. With default NaN initialization, the programmer is more likely to stop and think about it, not just insert 0. Another issue with it is:
For the purposes of code clarity I don't want to see a variable initialized to a value that is never used, just to shut the compiler up. | |||||||||||||||||
| |||||||||||||||||
| ▲ | lmm an hour ago | parent | prev [-] | ||||||||||||||||
Yep. This is NaN as a billion dollar mistake all over again. | |||||||||||||||||