【问题标题】:How can we shift ob_item pointer in Python tuple if it is static array?如果它是静态数组,我们如何在 Python 元组中移动 ob_item 指针?
【发布时间】:2015-04-14 21:28:02
【问题描述】:

我目前正在阅读 Python 2.7 源代码,但在tupleobject.h 中遇到了以下代码:

PyObject *ob_item[1];

tupleobject.c (PyTuple_SetItem):

p = ((PyTupleObject *)op)->ob_item + i;

如果ob_item 是一个PyObject 的数组,我们如何将指针移动i

【问题讨论】:

标签: python c python-2.7 python-internals


【解决方案1】:

这就是数组和指针可以互换使用的方式。所以相当于

p = &((PyTupleObject *)op)->ob_item[i];

Is an array name a pointer? 更详细一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多