Minor issue with understanding
There are two reasons why a variable might happen to be zero when uninitialized. It's not astronomically unlikely...
1) When things are compiled in debug mode, some C++ compilers will initialize memory to zero. Unfortunately when writing production software this means that the production code may behave differently from the debug code when an uninitialized variable is encountered, which delays the finding of any problems. After getting bitten by that once too often at my job, we have made it part of our code reviews to insist that variables always be initialized when they are declared, either from a constructor or (for simple types like int and pointers) explicitly. This quickly becomes second nature. (It also ensures that there aren't obscure paths through the code that leave a variable uninitialized.)
2) It can happen that, while not set explicitly, the nature of the code that runs prior to the variable being allocated on the stack or heap causes the memory to be initialized a certain way. Obviously, 0 has many special meanings (end of string, initial index, NULL pointer) that it shows up fairly often.
1) When things are compiled in debug mode, some C++ compilers will initialize memory to zero. Unfortunately when writing production software this means that the production code may behave differently from the debug code when an uninitialized variable is encountered, which delays the finding of any problems. After getting bitten by that once too often at my job, we have made it part of our code reviews to insist that variables always be initialized when they are declared, either from a constructor or (for simple types like int and pointers) explicitly. This quickly becomes second nature. (It also ensures that there aren't obscure paths through the code that leave a variable uninitialized.)
2) It can happen that, while not set explicitly, the nature of the code that runs prior to the variable being allocated on the stack or heap causes the memory to be initialized a certain way. Obviously, 0 has many special meanings (end of string, initial index, NULL pointer) that it shows up fairly often.
Measure twice, cut once, curse three or four times.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Understanding multisampled FBOs | Coyote | 12 | 7,075 |
Nov 27, 2009 01:01 AM Last Post: arekkusu |
|
| Understanding glColorMaterial | PhysicsGuy | 3 | 4,334 |
Nov 25, 2008 06:25 PM Last Post: PhysicsGuy |
|
| glTexImage2D() & memory understanding... | sealfin | 4 | 3,219 |
Aug 7, 2004 03:15 PM Last Post: OneSadCookie |
|

