【问题标题】:Strange C syntax in Lua libraryLua 库中奇怪的 C 语法
【发布时间】:2015-08-05 21:35:24
【问题描述】:

我在 torch library 的 C 代码中看到了类似 this 的函数:

long THTensor_(storageOffset)(const THTensor *self)
{
  return self->storageOffset;
}

这是一个预处理器的东西,还是 lua 特定的东西?我认为这个想法与storageOffsetTHTensor“类”上的某种方法有关,但我从未见过这种语法。

【问题讨论】:

标签: c lua torch


【解决方案1】:

这是一个预处理宏

lib/TH/THTensor.h:
#define THTensor_(NAME)   TH_CONCAT_4(TH,Real,Tensor_,NAME)

导致...

lib/TH/THGeneral.h.in:
#define TH_CONCAT_4(x,y,z,w) TH_CONCAT_4_EXPAND(x,y,z,w)

最后……

lib/TH/THGeneral.h.in:
#define TH_CONCAT_4_EXPAND(x,y,z,w) x ## y ## z ## w

因此,

long THTensor_(storageOffset)(const THTensor *self)

最终变成了这样:

long THRealTensor_storageOffset(const THTensor *self)

预处理器不只是grand吗?

【讨论】:

    猜你喜欢
    • 2013-11-29
    • 2017-12-06
    • 1970-01-01
    • 2016-03-03
    • 2016-08-26
    • 2012-03-14
    • 2012-12-17
    • 2012-10-12
    • 2010-11-24
    相关资源
    最近更新 更多