AttributeError on pointer dereferencing in loop target #1831
I was trying to use a "cleaver trick" in my very first attempt to write a Cython module, the code which failed to compile boils down to something like this:
While this form doesn't make sense in pure Python, in C it's an equivalent of using *ptr which is fine, so I was wondering if it would be possible to support it in Cython as well, at the very least it would be nice to have a more helpful error message.
The text was updated successfully, but these errors were encountered:
This is just an example of syntax which can be compiled and run, if you want a concrete example - I was trying to use it in asn.1 parser like this:
The first time I tried to cythonize file containing this piece of code I got an AttributeError and I had to comment out various parts to find what was causing it. So it would be nice to improve that part (error reporting) but if this gets be supported it would be even better.
Sorry, but I still don't understand it. Your example assigns to array index 0 as loop variable, and then uses array index 1 inside of the loop. What is the intention here? Do you really want to avoid the single code line that it would take to write this:
I can reproduce the
I was using this code:
We should probably allow any lvalue as the loop target, as in Python, and we should produce better errors. I don't, however, understand setting
So.. yes, scoder is right, I did that just to avoid using additional temporary variable, at least that is what I would have done in C code, where abusing pointers is morally acceptable behaviour.
Consider following example (which works as intended):
One might want to rewrite this function, remove struct and pass the pointers directly:
As I said, that's a bug. Thanks for reporting it and thanks for the clarifications.
Don't forget that there's a C compiler cleaning up after you. Aliasing it something that compilers learned decades ago.