[cfe-dev] Macro expansion with Clang

Richard Smith richard at metafoo.co.uk
Tue Oct 15 13:24:23 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?
>

One way:

#include "your_header.h"

int main() {
  printf("A = %d\nB = %d\n", A, B);
  return 0;
}

What additional constraints do you have? Do you need to do this using the
Clang C++ API for some reason? Do you know in advance the names of the
macros that you want to evaluate?

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.
>
> Thank you in advance.
>
> --
> Alexander
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131015/e71fdeba/attachment.html>


More information about the cfe-dev mailing list