[C++-sig] def_readonly and const array members

Jeff Brewer jeff at brewer.com
Fri Jul 25 00:35:01 CEST 2003

I am trying to wrap structs that have character arrays and I'm having
problems since I moved from MSVC 7 to MSVC 7.1 (VS .NET 2003). Here is
the struct I'm trying to expose the theArray member of using

struct testStruct
	unsigned char theArray[16];

I've created a to_python converter for the unsigned char [16] type but
I'm getting a "TypeError: No to_python (by-value) converter found for
C++ type: unsigned char const volatile [8]" when I try to access the
theArray member in Python. I've tried putting volatile in my typedef for
the array, but that doesn't seem to help (how C++ binds these type
modifiers always confuses me so maybe I put it in the wrong place).

Thank you for the help,

Jeff Brewer
jeff at purplemagma.com

p.s. The full code follows:

Python code:
import test
theStruct = test.getStruct()
print theStruct.theArray

C++ code:
typedef unsigned char uchar16array[16];
struct uchar16array_to_python	

	static PyObject *convert(uchar16array const &value)

PyObject *result = PyTuple_New(16);
		for (int i = 0; i < 16; i++)

		return result;

struct testStruct
	unsigned char theArray[16];

testStruct getStruct()
	static testStruct theStruct =

	return theStruct;

	to_python_converter<uchar16array, uchar16array_to_python>();

	class_<testStruct>("testStruct", init<>())
		.def_readonly("theArray", &testStruct::theArray);

	def("getStruct", getStruct);

More information about the Cplusplus-sig mailing list