Compile error: using cpdef enum and typedef enum
See original GitHub issueI observed a compilation error from clang-800.0.38 on a MacBook when using a c enum and a Cython cpdef enum. I could reproduce the issue using gcc version 4.9.2 (Raspbian 4.9.2-10). In both cases, Cython version 0.25.1 was used.
The code I ran was:
#lib.h
typedef enum { A, B, C, D} foo;
#lib.pyx
cdef extern from "./lib.h":
cpdef enum foo:
A, B, C, D
def t1():
for e in foo: print(e.name)
When trying to compile, clang throws a lot of errors which all seem to correlate with the “enum foo”.
A solution is to declare the enum in the .h file as following typedef enum foo { A, B, C, D} foo;
or as typedef enum foo { A, B, C, D};
. When changed, the code is compiled and linked to a .so file and is working as intended.
Is this intended behaviour or bug?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
What is the reason for this Cython compile error when ...
I want to use a cpdef enum which creates a PEP 435 style Python Enum (available since Python 3.4). This feature was introduced...
Read more >Developers - Compile error: using cpdef enum and typedef enum -
I observed a compilation error from clang-800.0.38 on a MacBook when using a c enum and a Cython cpdef enum. I could reproduce...
Read more >cpdef enums can't be shared - Google Groups
When using a normal cdef enum these compile errors do not occur. #lib.h. typedef enum { A, B, C, D } test;. #test.pyx....
Read more >What is the reason for this Cython compile error when ...
#lib.h file typedef enum { A, B, C, D } test; #lib.pyx file cdef extern from "lib.h": cpdef enum test: A, B, C,...
Read more >Compiler Warning (level 1) C4920 - Microsoft Learn
If a .tlb that you pass to #import has the same symbol defined in two or more enums, this warning indicates that subsequent...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 for some kind of “cptypedef”. Kinda ugly but I don’t see a better way…
Is
cptypedef
something that we can add?My current workaround is rather verbose, especially when there are a lot of enums values. It looks something like this:
My actual code is even more verbose because I prefix the ctypedef enum names so they don’t pollute the global namespace.