Dag Sverre Seljebotn wrote:
> Robert Bradshaw wrote:
>> On May 7, 2009, at 12:24 AM, Dag Sverre Seljebotn wrote:
>>> What I'm getting here at is that we are creating a distinction in
>>> Cython
>>> which actually does not exist in C++ (rather C++ adds member methods,
>>> constructors, private members, and vtables all as orthogonal and
>>> independent extensions).
>>>
>>> But I think that is how it should be.
>>
>> Yep, if C++ considers them different enough to allocate two separate
>> keywords for them, than so should we. (I think it'll also be less
>> confusing).
>
> But C++ doesn't!!
>
> class Foo {
> int x;
> public:
> int y;
> void z();
> };
>
> is EXACTLY the same as
>
> struct Foo {
> int y;
> void z()
> private:
> int x;
> };
>
> Whatever the distinction is supposed to be in Cython, it cannot be the
> default private/public, as only the public stuff is available to us
> anyway!
>
> I've been using the distinction to mean "these structs should be
> reference-counted, not have stack-allocated semantics like we use for C
> structs". If one doesn't plan to ever go for a reference counted scheme,
> we should just use plain struct.
Ok, so these are orthogonal goals, IIUC. In that case, I'd vote for plain
"struct" to avoid the ambiguity with Python's "class".
Then, struct methods would behave different for C and C++ semantics in
that the C++ code would call the class method, while the C code would use
the transformed plain function call. C struct methods can only be defined
in Cython (.pyx) code, whereas C++ struct methods can only be defined in
external C++ declarations.
Note that we can always switch to "class" or whatever other declaration
later on if we want to enable ref-counting and consider it similar enough
to Python's class behaviour. That would be an additional feature.
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev