dotdotdot cannot be used in typedefed arrays

Issue #285 resolved
Avi B
created an issue

dotdotdot cannot be used in typedefed arrays


ffi.set_source("typedef int MyArr[10 / 2];")
ffi.cdef("typedef int MyArr[...];")



  File "C:\Python27\lib\site-packages\cffi\", line 105, in cdef
    self._cdef(csource, override=override, packed=packed)
  File "C:\Python27\lib\site-packages\cffi\", line 119, in _cdef
    self._parser.parse(csource, override=override, **options)
  File "C:\Python27\lib\site-packages\cffi\", line 299, in parse
  File "C:\Python27\lib\site-packages\cffi\", line 335, in _internal_p
  File "C:\Python27\lib\site-packages\cffi\", line 512, in _get_type_a
    typenode.dim, partial_length_ok=partial_length_ok)
  File "C:\Python27\lib\site-packages\cffi\", line 763, in _parse_cons
    if isinstance(exprnode, pycparser.c_ast.Constant):
cffi.api.FFIError: :2: unsupported expression: expected a simple numeric constan
    *** Err: typedef int MyArr[__dotdotdotarray__];

Comments (10)

  1. Armin Rigo

    Can you be more precise? The syntax you're suggesting, i.e. literally typedef **struct** hello {...;} hello;, doesn't seem to make much sense... If you mean typedef struct hello {...;} hello; then it works fine as far as I know?

  2. KoshkinAlex31

    Asterisks are just my attempt to make bold text inside code block, sorry)
    exact code that fails:

    typedef enum fpta_value_type {
    } fpta_value_type;

    It fails with

    cffi.error.CDefError: cannot parse "__dotdotdot__ ;"
    :3:6: before: __dotdotdot__
  3. Armin Rigo

    The syntax ...; only works for structs and unions. For enums, you have to use ... instead. That's not really an inconsistency, given that in standard C code you never use ; inside an enum { } either.

  4. Log in to comment