[antlr-interest] Bug report; generated C(++) code inappropriately initialises non-primitive return values

Johannes Luber jaluber at gmx.de
Mon Mar 30 08:29:06 PDT 2009


Richard Thrippleton schrieb:
> Gary R. Van Sickle wrote:
>>> From: Richard Thrippleton
>>> the generated code for that rule will start with
>>>
>>> "std::vector<int> foo = NULL;"
>>>
>> Really, it adds that "= NULL" of its own volition?  That sounds like 
>> a bug. All kinds of C PODs (structs for instance) could be in there, 
>> none of which could be pointers, and that should then fail on C as 
>> well as C++.  What version is this?
> Yeah, I'm pretty mystified by this. I'm definitely not trying to NULL
> anything myself. By experimentation, it looks like it _tries_ to do the
> right thing for different datatypes e.g. it will 0 an int.

The templates contain a map structure which allows to set the default
values for a certain number of predefined types. The problem with this
approach is that it requires a language with only a limited number of
value types. Otherwise it uses the default initialization which assumes
 pointers. C# has solved the problem with using the default keyword
(which initializes structs with the default constructor, which is the
0-bit pattern, and for references simply null) but I don't think that
C(++) has an equivalent.

Johannes

>> Like I noted above, you will run into problems due to the malloc() 
>> vs. new thing.  At least I did the last time I tried it.
> Well, I guess this is good news for you then ... should Just Work on
> 3.1.1 and higher :-)
> 
> Richard
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 



More information about the antlr-interest mailing list