Strange C syntax in Lua library

I see functions like this in the torch library C code:

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

      

Is it a preprocessor or something special? The idea, I think, has to do with what storageOffset

is a sorting method in a THTensor

"class", but I've never seen such a syntax.

+3


source to share


1 answer


This is a preprocessor macro

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

      

that leads to...

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

      

and finally ...

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

      



Hence,

long THTensor_(storageOffset)(const THTensor *self)

      

eventually becomes this:

long THRealTensor_storageOffset(const THTensor *self)

      

Aren't preprocessors just great?

+8


source







All Articles