I had a problem trying to express a type pointer inside a macro.
Take this simple example.
#define INDEX_OF_DATA(data, type, index) \ ((type *)data)[index]
It works:
INDEX_OF_DATA(buffer, float, 3);
If this fails:
INDEX_OF_DATA(buffer, float[2], 3);
Since the cast should be (float(*)[2]) .
Is there a way to express a "pointer to type " ... without using typeof ? (which is not standard C).
Please note: there are, of course, other ways for this particular example to work. e.g. for char and offset by sizeof(type) * index . But I'm interested in a way to express pointer to type in C.
c c-preprocessor
ideasman42
source share