469,945 Members | 1,801 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

noddy example, writing C modules for python

Hi,

based on the example module "noddy" i wrote an own one
and i have problems accessing the elements in the python
objects. I defined the example object:

typedef struct {
PyObject_HEAD
int num;
} pmod_obj;
static PyMemberDef pmod_members[] = {
{"number", T_INT, offsetof(pmod_obj, num), 0, /* LINE 143 */
"pmod number"},
{NULL}
};

When i compile this under Win32, i get this (in german):
pmod.cc(143) : error C2552: 'pmod_members': Initialisierung nicht
zusammengesetzter Typen mit Initialisierungsliste ist nicht möglich
'PyMemberDef' : Typen mit benutzerdefinierten Konstruktoren sind
nicht 'aggregate'
pmod.cc(143) : error C2065: 'T_INT': nichtdeklarierter Bezeichner
pmod.cc(143) : error C2275: 'pmod_obj': Ungültige Verwendung dieses Typs als
Ausdruck
pmod.cc(10): Siehe Deklaration von 'pmod_obj'
pmod.cc(143) : error C2065: 'num': nichtdeklarierter Bezeichner
pmod.cc(143) : error C3861: 'offsetof': Bezeichner wurde auch mit einer
argumentbezogenen Suche nicht gefunden
Has anybody got a hint for me? It is not obvious to me why this
does not compile.
Best regards,
Torsten.

Jul 18 '05 #1
3 2314
On Sun, 30 May 2004 11:22:06 +0200, Torsten Mohr <tm***@s.netic.de>
wrote:
pmod.cc(143) : error C2065: 'T_INT': nichtdeklarierter Bezeichner
hmmm, looking at this makes me wonder if you need a:

#include "structmember.h"

since T_INT is defined there.
<{{{*>


Jul 18 '05 #2
> hmmm, looking at this makes me wonder if you need a:

#include "structmember.h"


Hi,

you are right. I did not expect that. I thought that
this would be included from Python.h, but obviously i
was wrong.
Thanks for that hint,
Torsten.

Jul 18 '05 #3
Hi Torsten,

On Sun, 30 May 2004, Torsten Mohr <tm***@s.netic.de> wrote:
based on the example module "noddy" i wrote an own one
and i have problems accessing the elements in the python
objects. I defined the example object: typedef struct {
PyObject_HEAD
int num;
} pmod_obj;
static PyMemberDef pmod_members[] = {
{"number", T_INT, offsetof(pmod_obj, num), 0, /* LINE 143 */
"pmod number"},
{NULL}
};
When i compile this under Win32, i get this (in german):
pmod.cc(143) : error C2552: 'pmod_members': Initialisierung nicht
zusammengesetzter Typen mit Initialisierungsliste ist nicht mglich
'PyMemberDef' : Typen mit benutzerdefinierten Konstruktoren sind
nicht 'aggregate'


The explanation is shown quite clear in plain German - where is your
problem? :-) One is sure: your problem has nothing to do with Python
but with C++. Only for short, look at this example:

#v+
class A {
public:
char *s;
A(): s("") {}
} a = {"Hallo"};
#v-

That cannot compile too because there are two different
initializations: one via constructor and the second via initialization
list. So, of course, Gnu g++ also complains:

test.cc:24: error: `a' must be initialized by constructor, not by `{...}'

HTH & f'up2

Bernd

--
Those who desire to give up freedom in order to gain security,
will not have, nor do they deserve, either one. [T. Jefferson]
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Uwe Grauer | last post: by
2 posts views Thread by Xah Lee | last post: by
20 posts views Thread by Xah Lee | last post: by
4 posts views Thread by John Pote | last post: by
13 posts views Thread by gonzlobo | last post: by
3 posts views Thread by Kinokunya | last post: by
1 post views Thread by Terry Reedy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.