擅长:python、mysql、java
<p>对于那些通过谷歌来到这里的人,我找到了解决办法。如果你有一个结构:</p>
<pre><code>typedef struct {
union {
int a;
struct {
int b;
int c;
};
}
} outer;
</code></pre>
<p>你可以在Cython声明中把它弄平,就像这样:</p>
^{pr2}$
<p>Cython生成的代码不会对结构的内存布局做出任何假设;您只是告诉它要生成什么样的语法来调用它,从而告诉它实际的调用结构。因此,如果您的结构有一个大小为<code>int</code>的成员,可以作为<code>((outer) x).a</code>访问,那么您可以在结构定义上抛出<code>a</code>,它就可以工作了。它操作的是文本替换,而不是内存布局,所以它不关心这些东西是在匿名联合还是在结构中,或者是什么。在</p>