[cfe-dev] Macro expansion with Clang
James Dennett
james.dennett at gmail.com
Tue Oct 15 11:13:22 PDT 2013
On Mon, Oct 14, 2013 at 9:48 PM, Alexander Basov <coopht at gmail.com> wrote:
> Hello.
> Could somebody help me with macro expansion?
>
> I have a header with the following macroses defined:
>
> #define foo(x) x + 2
> #define A 1
> #define B foo(A)
>
> And I need get the following map:
> A = 1
> B = 3
>
> How can I do it?
>
> I'm ale to get list of MacroInfo * classes with PPCallbacks or get it with
> Preprocessor::macro_begin() iterator, but I don't know how to get expaneded
> value.
I think you may be looking in the wrong places, or at least not in all
of the right places.
The expanded value of "B" is "A + 2", not "3". Macro expansion
doesn't evaluate arithmeic.
If you want to get the value 3 for "B", you need to expand and then
evaluate the preprocessor constant expression "B", as is done in
processing the #if directive.
-- James
More information about the cfe-dev
mailing list