On 20 Oct 2007, at 02:40, David Fang wrote:
I've just encountered a problem where the compiler rejects
bison's prototype for "void* malloc(YYSIZE_T);" because it
doesn't match with <stdlib.h>, which looks like "void* malloc
(size_t) __THROW ... ;" (ubuntu7). The problem only manifests
when compiling the resulting source file as in C++ (otherwise,
the __THROW macro is empty). It looks like the bison skeleton is
using "defined __cplusplus" to conditionally insert this
prototype, rather than including <cstdlib>, a standard C++
wrapper header, which should resolve the inconsistency, and be
safely portable.
This issue is the same on at least 2.1 and 2.3. Does anyone
else see this issue on ubuntu7 or other UNIX system? (Another
ubuntu7 distro didn't have this issue, so I need to get more
feedback from my bug reporter.)
Well, is it the C or C++ header? In C++, standard names start with
"std::".
The error message was pointing to "the original declaration" in /
usr/include/stdlib.h, which already contained provisions for C++
(namespace, no-throw specification) without going through
<cstdlib>. In any case, the prototype mismatch is attributed to
the difference in the throw specification, which is missing from
the bison skeleton's version (not any other issue). The quick fix
I see is to just include <stdlib.h> or if __cplusplus, <cstdlib>.
If this results in std::malloc, then a conditional definition of a
"std::" namespace prefix should take care of calls to malloc in C++
mode. Thoughts?
Actually, I misspoke about the platform: it was occuring on ubuntu6
not 7.
I meant: do you Bison-compile to generate C or C++ output.
Once upon the time, the C output had informal support for C++, but
that was dropped, I think. The "if __cplusplus" suggests you have
some compile for C that does not work with C++.
Hans Aberg
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison