[C++-sig] Re: extract<const char *>

David Abrahams dave at boost-consulting.com
Thu Dec 18 19:32:49 CET 2003

"Niall Douglas" <s_sourceforge at nedprod.com> writes:

> If I do this:
> list result; // some python list
> printf("List from C++ is %s\n", extract<const char *>(str(result)));
> ... the string appear to be corrupted. Yet if I remove the printf() 
> and extract to a const char *, the string is correct.
> Where does extract<> store its result?

It doesn't.  You're getting the char const* out of the temporary
Python string you created.  This is the same as the "attempt to return
a dangling reference" issue.  If you want something that will stick
around, extract std::string.

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list