Pregunta

I'm wondering if the preprocessor (specifically the one shipped in Xcode's LLVM) is able to do something like this:

#define CAPS_SYMBOL(x) ...

where this preprocessor statement in code:

int CAPS_SYMBOL(lala) = 1;

would output the following valid compilable code:

int Lala = 1;

The end goal of what I want to do is to make a macro that does this, given that some mechanism for CAPS_SYMBOL exists:

#define MAKE_WEAK_VAR(x) __weak __typeof(x) weak ## CAPS_SYMBOL(x) = x

Is this possible? If so, how does one do it?

¿Fue útil?

Solución

No, the preprocessor can not capitalize tokens. But you could define

#define MAKE_WEAK_VAR(x) __weak __typeof(x) weak ## x = x

instead. Then for example

MAKE_WEAK_VAR(self);

expands to

__weak __typeof(self) weakself = self;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top