.cdef() does not support (1<<0) in enums

Issue #174 new
Former user created an issue

So I can't simply copy-paste

typedef enum { GIT_REPOSITORY_OPEN_NO_SEARCH = (1 << 0), GIT_REPOSITORY_OPEN_CROSS_FS = (1 << 1), GIT_REPOSITORY_OPEN_BARE = (1 << 2), } git_repository_open_flag_t;

Comments (7)

  1. Armin Rigo

    Unclear that we want to go in this direction: we should then support any arithmetic expression, involving constants defined as macros, etc.

    If you're using the API mode, anyway, you can replace all of these expressions with .... We could even ignore the expression and automatically interpret it as ..., but that's bound to give obscure errors sometimes. I understand the 'problem' of not being able to copy-and-paste, but 'replace some bits with dot-dot-dot' is part of the generally recommended approach...

  2. realitix

    Although the copy/paste is not the preferred way, it's very useful when you use the cpp command to do the preprocessing work for you. I'm currently building the cffi wrapper of BulletPhysics library, and I need to automatically generate the header file. I could write a small cleaner script but if I can stick with cpp, it's better. Sadly, this arithmetic syntax is often used in C enums. So I think it's a very important feature.

    Thanks Armin.


  3. Armin Rigo

    This feature has been the topic of several pull requests. Sadly, for all these pull requests I had "complains" asking for further fixes and the original author just disappeared. Please don't take this particular history as meaning I never accept pull request. If you want to offer another fully-tested pull request that does exactly what the present issue asks for and nothing more, it will be certainly accepted.

    There are a few issues that make it not-so-obvious: the expression 1 << 31 generally means -2147483648 in C.

  4. Log in to comment