I'd like to repeat a block of C code N
times, every time just changing just a few words (like variable names, variable types...).
I'd like to obtain a final effect similar to NumPy's preprocessor for .src
files. For example in their code you can see that this:
/**begin repeat
* #name = number, integer, signedinteger, unsignedinteger, inexact,
* floating, complexfloating, flexible, character#
* #NAME = Number, Integer, SignedInteger, UnsignedInteger, Inexact,
* Floating, ComplexFloating, Flexible, Character#
*/
NPY_NO_EXPORT PyTypeObject Py@NAME@ArrType_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "numpy.@name@",
.tp_basicsize = sizeof(PyObject)
};
/**end repeat**/
would be turned into something like this:
NPY_NO_EXPORT PyTypeObject PyNumberArrType_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "numpy.number",
.tp_basicsize = sizeof(PyObject)
};
NPY_NO_EXPORT PyTypeObject PyIntegerArrType_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "numpy.integer",
.tp_basicsize = sizeof(PyObject)
};
NPY_NO_EXPORT PyTypeObject PySignedIntegerArrType_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "numpy.signedinteger",
.tp_basicsize = sizeof(PyObject)
};
// And so on for all the couples of `name` and `NAME`.
Is there a way to do the same thing, but without having to use an external preprocessor? I thought about using macros but I don't think that's the case.