寻求澄清 Python CFFI 定义文件中 "empty" C 结构定义的有效性和原因

Clarification sought on validity and reason for "empty" C struct definition in Python CFFI definition file

我正在阅读一些 code,并遇到了这个相当奇怪的 C 结构定义:

typedef struct dataObject
  {
      ...;
  } DATA_OBJECT;

任何人都可以解释一下(如果可能,请提供参考):

  1. 如果这是一个有效的结构定义。
  2. 这样定义的目的是什么(没有定义 fields/members)。
  1. If this is a valid struct definition

不,不是。抓取部分C17 6.7.2.1形式语法:

struct-declaration:
specifier-qualifier-list struct-declarator-listopt ;
static_assert-declaration

因此,首先,该结构需要包含一个“说明符-限定符列表”,用简单的英语来说就是变量名之前的 const int 等内容。由于这不存在,例如 gcc 抱怨语法错误:

error: expected specifier-qualifier-list before '...' token


2.What would be the purpose of such a definition (where no fields/members are defined)?

我猜它要么是伪代码,要么是开发人员“TODO”,他们在其中提交了无法编译的代码,因为它尚未编写。

If this is a valid struct definition

没有

What would be the purpose of such a definition (where no fields/members are defined)?

该文件的目的是为 python CFFI 解析器提供要使用的类型和函数声明。

这个文件的目的是通过python CFFI ffibuilder.cdef(). From letting C compiler fill the gaps:

预处理

Moreover, you can use “...” (literally, dot-dot-dot) in the cdef() at various places, in order to ask the C compiler to fill in the details. These places are:

  • structure declarations: any struct { } or union { } that ends with “...;” as the last “field” is partial: it may be missing fields, have them declared out of order, use non-standard alignment, etc. Precisely, the field offsets, total struct size, and total struct alignment deduced by looking at the cdef are not relied upon and will instead be corrected by the compiler. (But note that you can only access fields that you declared, not others.) Any struct declaration which doesn’t use “...” is assumed to be exact, but this is checked: you get an error if it is not correct.
  • [...]
  • unknown types: [....] In some cases you need to say that foo_t is not opaque, but just a struct where you don’t know any field; then you would use typedef struct { ...; } foo_t;.

我怀疑这对 CFFI 意味着 struct dataObjectDATA_OBJECT 是不透明类型,仅用作指针,CFFI 解析器不支持结构声明。

根据我的理解,该文件用于 here in clips_build.py 构建 clipspy python 到 C 的接口。