[cfe-dev] Macro expansion with Clang

Edward Diener eldlistmailingz at tropicsoft.com
Tue Oct 15 16:09:34 PDT 2013


On 10/15/2013 2:13 PM, James Dennett wrote:
> 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.

That is not correct. Invoking B gives "1 + 2".





More information about the cfe-dev mailing list