[cfe-dev] Macro expansion with Clang

Alexander Basov coopht at gmail.com
Tue Oct 15 21:32:06 PDT 2013


Could you point me out to some example how can I do that?


2013/10/16 James Dennett <james.dennett at gmail.com>

> On Tue, Oct 15, 2013 at 4:09 PM, Edward Diener
> <eldlistmailingz at tropicsoft.com> wrote:
> > 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".
>
> Sorry, indeed; that was a typo.  My brain fully expanded the macro,
> but my fingers somehow stopped after one level.  Fortunately I don't
> think it's material.
>
> The point still stands: if you want the value, not the expansion, you
> need to do evaluation.
>
> -- James
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>



-- 
Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131016/6da6a058/attachment.html>


More information about the cfe-dev mailing list