[Cython] Declaration syntax change

Stefan Behnel stefan_ml at behnel.de
Thu Oct 3 14:23:25 CEST 2013


Greg Ewing, 03.10.2013 14:10:
> Robert Bradshaw wrote:
>>     cdef int *a, b, c, *d[3]
>>
>> is IMHO quite ugly but also adds a lot of complexity to the parser.
>> What if instead we required
>>
>>     cdef int* a
>>     cdef int b, c
>>     cdef int[3]* d

The last line looks ambiguous, BTW, hadn't even noticed it before. Is that
an array of int pointers or a pointer to an array (pointer)? We should make
sure the way this is declared is really obvious and not unexpected to C users.


> What would be the benefit of this? You're proposing to change
> from something identical to C declaration syntax, which is
> second nature for a great many people, to something that
> looks deceptively like C syntax but isn't.

The reasoning is that the C syntax is error prone and less readable than it
could be, because you have to spot stars in the right places of a
potentially long list of variable names to know if something is a value or
a pointer. If there was only one type declaration, right after the cdef, it
would be much clearer. It would just say: "this is a list of variables
declared as int*", not mixing any further types into it.

Also, C is only second nature to some people. A great many people actually
use Cython specifically to *avoid* having to write C.

Stefan



More information about the cython-devel mailing list