3 ms·
Isn't x already initialized to zero as it's static? I googled it and this[0] seemed relevant: 1655 — if it has arithmetic type, it is initialized to (positiv
by smhenderson 10y ago
Isn't x already initialized to zero as it's static?
I googled it and this[0] seemed relevant:
1655 — if it has arithmetic type, it is initialized to (positive or unsigned) zero;
[0] http://c0x.coding-guidelines.com/6.7.8.html http://c0x.coding-guidelines.com/6.7.8.html
- nkurz 10y ago> Isn't x already initialized to zero as it's static? If x was static, this would be true. But in this case, x is just a default automatic variable. For x to be static, it would have to be declared outside the function, or have the keyword 'static'.
- smhenderson 10y agoOK, thanks, appreciate the correction. I see what I had wrong now. For anyone else interested in a longer explanation these SO comments are pretty informative: http://stackoverflow.com/questions/14049777/why-are-global-variables-always-initialized-to-0-but-not-local-variables#14049791 http://stackoverflow.com/questions/14049777/why-are-global-v...
- gsg 10y agoWhat you want is just a few lines up: 1652 If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. (x is an 'auto' variable in the given program.)
- smhenderson 10y agoYeah, that's what I get for replying without making sure I'm correct! :-)