【问题标题】:How to use inline function in Cython [closed]如何在 Cython 中使用内联函数 [关闭]
【发布时间】:2014-01-02 11:45:52
【问题描述】:

我是 Cython 的新手,在编译内联函数时遇到问题。简化代码为:

cdef inline REG8(ulong addr):
   (<volatile_uchar_ptr *>(addr))[0]

我正在尝试在 Python 方法中使用内联函数:

def test(self):
    REG8(addr) = 0x08                         # ==> Error: "Cannot assign or delete this".
    (<volatile_uchar_ptr *>(addr))[0] = 0x08  # ==> OK. 

当我使用内联函数REG8() 时,我得到编译器错误: Cannot assign or delete this。但是,插入的代码将起作用。我不知道这里出了什么问题,如果有任何帮助,我将不胜感激。

【问题讨论】:

    标签: python pointers inline cython


    【解决方案1】:

    你错过了[0]

    REG8(addr)[0] = 0x08
    

    您分配给函数调用,而不是它指向的值。

    【讨论】:

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