Module Extension C/CPI Question

"Martin v. Löwis" martin at v.loewis.de
Wed Aug 10 19:07:34 CEST 2005


Jeremy Moles wrote:
> typedef struct Foo {
> 	int x;
> 	int y;
> 	int z;
> 	char xyz[100];
> } Foo;
> 
> Is there an "accepted" way of propagating this upstream? I was thinking
> one of these two:

It really depends on the struct. Would a C programmer automatically
be able to list all members, in their natural order? If they are
'x','y','z', I would say 'yes': it's obviously a point in a cartesian
coordinate system. If the members are readily known, and if you
would not use one without the others, a tuple is the right structure.

If, on the other hand, different applications would access different
fields, and if there are many fields so nobody could memorize them,
you would be better off with named access. A dictionary would work,
but people would prefer attribute names.

A typical example is the result of os.stat(), which is a type
named stat_result these days. It used to be a tuple, but that was
very inconvenient. For backwards compatibility, it had to remain
tuple-like, so we now have the StructSeq mechanism. This might
be the easiest way to get a struct-like value back to Python.

Regards,
Martin



More information about the Python-list mailing list