Static pointer not NULL at startup?
I can''t seem to work out why "sometimes" my app seems to start it''s static as 0x000000C rather than NULL... This is too early in the app to be a stray pointer...
Any idea''s?
Chris
Chris Brodie
Do you set it to 0x0 at definition? If not, it''ll have whatever crap is in ram at start up.
is it a static member of class?
is it a static member of class?
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I''m not sure but depending on the situation (compiler, etc.), newly declared pointers may be considered to have "undefined" values... that is, not necessarily NULL, but certainly nothing meaningful. For pointers just init them to NULL in the variable declaration (type* var = NULL; or something).
Creativity is a bloody nuisance and an evil curse that will see to it that you die from stress and alcohol abuse at a very early age, that you piss off all your friends, break appointments, show up late, and have this strange bohemian urge (you know that decadent laid-back pimp-style way of life). The truly creative people I know all live lousy lives, never have time to see you, don't take care of themselves properly, have weird tastes in women and behave badly. They don't wash and they eat disgusting stuff, they are mentally unstable and are absolutely brilliant. (k10k)
static pointer variables are initialized to NULL if a value is not explicitly given (ANSI sec 6.7.8 part 10). If you''re getting a static pointer that''s not NULL at initialization, then something is wrong. Perhaps a stack corruption, or an out-of-bounds write, or maybe even a broken compiler.
Ah, nice to have an official word. Just remember that MSVC is not ANSI compliant in many respects - yes, largly so, but just browsing the documentation you''ll find numerous spots where it mentions compliance issues. I''m not saying that this particular situation is such a case.. but it''s a good thing to remember.
Creativity is a bloody nuisance and an evil curse that will see to it that you die from stress and alcohol abuse at a very early age, that you piss off all your friends, break appointments, show up late, and have this strange bohemian urge (you know that decadent laid-back pimp-style way of life). The truly creative people I know all live lousy lives, never have time to see you, don't take care of themselves properly, have weird tastes in women and behave badly. They don't wash and they eat disgusting stuff, they are mentally unstable and are absolutely brilliant. (k10k)
Well, the MSVC documentation states explicitly that any variable with the static modifier is initialized to 0 unless otherwise specified. Not that it isn''t possible that the compiler doesn''t follow it''s own documentation (wouldn''t be the first time). However in this case, I suspect that the compiler is doing it''s job right. 0x000000C looks very similar to the value thrown by the null-pointer exception when run within the debugger. Ignore this if you happen to be using a non MSVC compiler (Borland''s null pointer exception, for example, looks very different).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement