[cfe-dev] Macro expansion

Nathan James via cfe-dev cfe-dev at lists.llvm.org
Sun May 31 03:58:41 PDT 2020


Unfortunately the pre processor amounts to not much more than text
manipulation and as such it won't evaluate expressions. In your example
`C` will hold the value `16/4`. If you want to have more than that,
then you will likely need to add a pre-build step to your build
process, Similar(but very different) to TableGen.

Nathan James

On Sun, 2020-05-31 at 15:43 +0530, Nagaraju Mekala via cfe-dev wrote:
> Hello All,
> I have a situation to expand a macro and I have succeeded by
> extracting a constant value using clang::MacroInfo
> getReplacementToken(0)
> But if a user gives a expression then how can we evaluate the macro
> value?
> ex:
> #define S 16
> #define O 4
> #define C S/O
> In the above example I need the evaluate S/O expression and use the
> value for my processing.
> Can someone point how can we do this?
> Thanks in advance.
> -Nagaraju
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

More information about the cfe-dev mailing list