[antlr-interest] 0xcdcdcdcd myth with antlr base tree pointer u

Gavin Lambert antlr at mirality.co.nz
Fri Jun 26 14:21:58 PDT 2009


At 05:24 27/06/2009, Xie, Linlin wrote:
>I've noticed that that empty pointers are all (am I right?) 
>initialized to be 0xcdcdcdcd by default. Looks like it's a 
>debugging value coming from the C runtime library. I wonder if 
>you have your reason for this to work this way, or better to 
>initialize them to be 0? it'd be helpful for us that we don't 
>have to check against this value which is perhaps not platform 
>independent.

The MSVC debug CRT initialises newly-allocated memory to 0xCD and 
freed memory to either 0xCC or 0xDD.  You should never rely on 
this behaviour, though -- it is neither portable nor consistent 
(by design), and the release-mode CRT behaves differently.  (The 
intent is to cause crashes in debug mode if using uninitialised or 
freed memory, since crashes are easier to find than invalid 
behaviour from acting on bad data.)

If you want to be able to ask "have I set a value for this" later 
on, then you *must* initialise the values yourself (typically to 0 
or NULL) as soon as possible after they are allocated.



More information about the antlr-interest mailing list