in reply to Re: C macro pre processing
in thread C macro pre processing

As far as I understand gcc -E , it expands all macros to their definition, while the OP seems to want to only remove the parts that vanish due to their guarding #define being false or not defined.

That doesn't fit the problem description, but it might well be the solution the OP wants.

Replies are listed 'Best First'.
Re^3: C macro pre processing
by BrowserUk (Patriarch) on Jun 24, 2012 at 07:56 UTC

    Ah! Yes, I can see the utility of such a tool. It would be very useful when exploring complex code.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      unifdef looks promising.

      Update:

      The current unifdef-2.6 does not process the #defines included from types.h, so for the trivial command unifdef types.c -o output.txt, the output is unchanged.

      Using the brain to parse types.h, one can define ALPHA, BETA, and GAMMA via the command line: unifdef -DALPHA=1 -DBETA -DGAMMA=0 types.c -o output.txt, but unfortunately, this removes all preprocessor commands, not only the GAMMA commands.

      So, to get rid of only the GAMMA commands, one has to define only GAMMA on the command line: unifdef -DGAMMA=0 types.c -o output.txt. This gives the expected result.

      Update 2:

      unifdef seems to completely ignore #include and #define. So, types.h is not read at all, and even if it would be read, the #defines have no effect.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)