[cfe-dev] Macro expansion with Clang

Richard legalize at xmission.com
Tue Oct 15 12:58:58 PDT 2013


In article <CAKNGpgr5Djj-Dvrvp=h5ubkSjF2Bz_PAi0+_+oAbk-4HJHNObg at mail.gmail.com>,
    James Dennett <james.dennett at gmail.com> writes:

> On Mon, Oct 14, 2013 at 9:48 PM, Alexander Basov <coopht at gmail.com> wrote:
> > #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?
>
> 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.

Is there a way for clang to expand the macros all the way down so that
he can get B as "1 + 2"?
-- 
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://computergraphicsmuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>



More information about the cfe-dev mailing list