Python ctypes和char**

Doo*_*Dah 5 python ctypes

我在C中有以下结构:

struct wordSynonym
{
    wchar_t* word;
    char** synonyms;
    int numSynonyms;
};

struct wordList
{
    wordSynonym* wordSynonyms;
    int numWords;
};
Run Code Online (Sandbox Code Playgroud)

而且,我在Python中有以下内容:

class wordSynonym(Structure):
    _fields_ = [ ("word", c_wchar_p),
                  ("synonyms", POINTER(c_char_p)), # Is this correct?
                  ("numSynonyms", c_int) ];

class WordList(Structure):
    _fields_ = [ ("wordSynonyms", POINTER(wordSynonym)),
                 ("numWords", c_int)];
Run Code Online (Sandbox Code Playgroud)

char**在python中引用的正确方法是什么?也就是说,在Python代码中,是否POINTER(c_char_p)正确?

iab*_*der 5

我在我的代码中使用它:

POINTER(POINTER(c_char))
Run Code Online (Sandbox Code Playgroud)

但我认为两者是等价的。

编辑: 实际上它们不是 http://docs.python.org/2/library/ctypes.html#ctypes.c_char_p

ctypes.c_char_p 表示指向以零结尾的字符串时的 C char * 数据类型。对于也可能指向二进制数据的通用字符指针,必须使用 POINTER(c_char)。构造函数接受整数地址或字符串。

SoPOINTER(POINTER(c_char))对于二进制数据来说POINTER(c_char_p)是一个指向 C 空终止字符串的指针。