Вопрос

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?

Это было полезно?

Решение

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;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top