FordPrefect had it right .. which is ALMOST what i posted (much less formally) in another post .. which I think bitmaster read and fliped around ...
NOTE: please understand, the reason the debugger initializes to 0xC0 is to make it very obvious when you use uninitialized memory ... cause if you are stepping though a function and see a variable with value 0xC0 get assigned into another variable first time through a loop or something .. it''s pretty suspect ... notice how much better that is than ZERO .. which is the norm anyway .. and therefore no help in debugging.
NOTE ALSO: you should NOT initialize any variable to an invalid or meaningless value, just to keep it from being random, as OldManDave said ... this wastes code .. but MOST importantly it fakes the compiler out ... so instead of getting a warning on the following
int x;
y = slope * x;
this:
int x = 0;
y = slope * x;
compiles silently, completely hiding the fact that it may not be what you wanted to do ... so ... initalize varaible WHEN you have the appropriate value with which to do so ... and NO SOONER ... this is similar to the rule of NOT SHARING for loop variables if their operation is completely seperate, this way small changes in code, don''t have strange repurcussions. It''s really crazy to see that C allowed declaration of for loop varaible, and then brings it into the outer scope if needed, the C++ way (which MS does NOT implement) is much better. If anyone has ever coded in assembly, you know that the a major point of high level languages was to prevent side effect behaviors due to register sharing errors (changing a register in a function and returning values ... while the caller incorectly uses the result as the pre call value .. etc)
variable before initialization
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement