问题描述
我收到的模仿在另一个文件中使用特定行的错误。
I am getting an error on a specific line that mimics the usage in another file.
PyObject *pyCharGetHeight(PyChar *self, void *closure) {
CHAR_DATA *ch = PyChar_AsChar((PyObject *)self);
PyObject *height = NULL;
if(ch != NULL) height = Py_BuildValue("s", charGetHeight(ch));
return height;
}
PyChar_addGetSetter("height", pyCharGetHeight, NULL, "Returns character's height");
将返回下面的错误,PyChar_addGetSetter ...行
is returning the following error, PyChar_addGetSetter... line
错误:预期的声明说明符或Ⅰ型的字符串常量前
我使用的是以下包括:
#include <Python.h>
#include "../scripts/pychar.h"
和pychar.h确实定义PyChar_addGetSetter()为原型这里:
And pychar.h does define PyChar_addGetSetter() as prototyped here:
void PyChar_addGetSetter(const char *name, void *g, void *s, const char *doc);
该功能是写在 ../脚本/ pychar.c 的如下:
void PyChar_addGetSetter(const char *name, void *g, void *s, const char *doc) {
// make sure our list of get/setters is created
if(pychar_getsetters == NULL) pychar_getsetters = newList();
// make the GetSetter def
PyGetSetDef *def = calloc(1, sizeof(PyGetSetDef));
def->name = strdup(name);
def->get = (getter)g;
def->set = (setter)s;
def->doc = (doc ? strdup(doc) : NULL);
def->closure = NULL;
listPut(pychar_getsetters, def);
}
这似乎是一个结构或类型不被认可,我猜我的功能。
It seems like a structure or type is not being recognized, I am guessing my function.
推荐答案
它看起来像你想在.c文件的顶层调用函数。你不能做到这一点。
It looks like you're trying to call a function at the top level of a .c file. You can't do that.
该错误消息可能是一个更好一点,但它看起来像GCC是间preting这是试图说明一个名为 PyChar_addGetSetter
和/或类型声明该类型的全局变量,并不能跨preT它无论哪种方式,并且告诉你为什么试图failde。
The error message could be a little nicer, but it looks like gcc is interpreting this as an attempt to declare a type named PyChar_addGetSetter
and/or to declare a global variable of that type, and failing to interpret it either way, and telling you why that attempt failde.
这篇关于错误:预期的声明说明符或'...'字符串常量前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!