Python ctypes和char**

2024-04-25 21:15:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我在C语言中有以下结构:

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

struct wordList
{
    wordSynonym* wordSynonyms;
    int numWords;
};

我在Python中有以下内容:

^{pr2}$

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


Tags: 方法代码结构structwordintsynonymswordlist
1条回答
网友
1楼 · 发布于 2024-04-25 21:15:35

我在代码中使用这个:

POINTER(POINTER(c_char))

但我认为两者是等价的。在

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

ctypes.c_char_p Represents the C char * datatype when it points to a zero-terminated string. For a general character pointer that may also point to binary data, POINTER(c_char) must be used. The constructor accepts an integer address, or a string.

因此POINTER(POINTER(c_char))用于二进制数据,POINTER(c_char_p)是指向以C null结尾的字符串的指针。在

相关问题 更多 >

    热门问题