-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Syntax error in C array declaration and initialization #5179
Comments
Just a thought. Should Cython support both syntaxes to declare array? cdef int arr1[4] # C style array declaration
cdef int[4] arr1 # Java style array declaration it seems that both of them generate same C code but the Java style (
Hence my proposal is following: Soft-deprecate C style definition - use only Java style array definition ( Any thoughts? [1] https://cython.readthedocs.io/en/latest/src/userguide/memoryviews.html |
Fair enough. BTW, Java style However, the documentation said:
which will generate warnings:
IMO it's better to mention it in the documentation. |
I'll leave this open for now. I think I'd accept a simple parser change to make the other syntax work. But I suspect it's low priority and may not happen |
I was just wondering how would I declare an array of pointers with java style declaration. I stumbled across this while trying to fit some linked lists in an array. cdef Node *data[4]
data = [NULL, NULL, NULL, NULL] This is the only way that I can think of initialising data for now. cdef Node*[4] data = [NULL, NULL, NULL, NULL] |
This should work:
… cdef Node* data = [NULL, NULL, NULL, NULL]
|
Doing |
If I understand correctly, "soft-deprecating" something doesn't mean that we will actually deprecate it. "soft-deprecated" only means it's not recommended, but will be still supported without any warnings. So if you really need the C style syntax, you can use it as expected, it's OK. However, I agree that: cdef Node*[4] data = [NULL, NULL, NULL, NULL] can be a useful feature that will improve code consistency. |
Yes. It should be the preferred way and should be used in all examples in documentation. |
Describe the bug
I found it in #5177.
This code doesn't compile:
But these two do:
I think it is already known, because it has been mentioned in the documentation:
cython/docs/src/userguide/language_basics.rst
Lines 124 to 129 in b2cad76
but I couldn't find the related issue.
Anyway, if it can't be fixed easily, it will be good to document it more clearly.
Code to reproduce the behaviour:
No response
Expected behaviour
No response
Environment
Cython version: both
0.29.32
and3.0.0a11
Additional context
No response
The text was updated successfully, but these errors were encountered: