Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 123413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:16:58+00:00 2026-05-11T04:16:58+00:00

Original Question What I’d like is not a standard C pre-processor, but a variation

  • 0

Original Question

What I’d like is not a standard C pre-processor, but a variation on it which would accept from somewhere – probably the command line via -DNAME1 and -UNAME2 options – a specification of which macros are defined, and would then eliminate dead code.

It may be easier to understand what I’m after with some examples:

#ifdef NAME1 #define ALBUQUERQUE 'ambidextrous' #else #define PHANTASMAGORIA 'ghostly' #endif 

If the command were run with ‘-DNAME1’, the output would be:

#define ALBUQUERQUE 'ambidextrous' 

If the command were run with ‘-UNAME1’, the output would be:

#define PHANTASMAGORIA 'ghostly' 

If the command were run with neither option, the output would be the same as the input.

This is a simple case – I’d be hoping that the code could handle more complex cases too.

To illustrate with a real-world but still simple example:

#ifdef USE_VOID #ifdef PLATFORM1 #define VOID void #else #undef VOID typedef void    VOID; #endif /* PLATFORM1 */ typedef void *  VOIDPTR; #else typedef mint     VOID; typedef char *  VOIDPTR; #endif /* USE_VOID */ 

I’d like to run the command with -DUSE_VOID -UPLATFORM1 and get the output:

#undef VOID typedef void    VOID; typedef void *  VOIDPTR; 

Another example:

#ifndef DOUBLEPAD #if (defined NT) || (defined OLDUNIX) #define DOUBLEPAD 8 #else #define DOUBLEPAD 0 #endif /* NT */ #endif /* !DOUBLEPAD */ 

Ideally, I’d like to run with -UOLDUNIX and get the output:

#ifndef DOUBLEPAD #if (defined NT) #define DOUBLEPAD 8 #else #define DOUBLEPAD 0 #endif /* NT */ #endif /* !DOUBLEPAD */ 

This may be pushing my luck!

Motivation: large, ancient code base with lots of conditional code. Many of the conditions no longer apply – the OLDUNIX platform, for example, is no longer made and no longer supported, so there is no need to have references to it in the code. Other conditions are always true. For example, features are added with conditional compilation so that a single version of the code can be used for both older versions of the software where the feature is not available and newer versions where it is available (more or less). Eventually, the old versions without the feature are no longer supported – everything uses the feature – so the condition on whether the feature is present or not should be removed, and the ‘when feature is absent’ code should be removed too. I’d like to have a tool to do the job automatically because it will be faster and more reliable than doing it manually (which is rather critical when the code base includes 21,500 source files).

(A really clever version of the tool might read #include‘d files to determine whether the control macros – those specified by -D or -U on the command line – are defined in those files. I’m not sure whether that’s truly helpful except as a backup diagnostic. Whatever else it does, though, the pseudo-pre-processor must not expand macros or include files verbatim. The output must be source similar to, but usually simpler than, the input code.)

Status Report (one year later)

After a year of use, I am very happy with ‘sunifdef‘ recommended by the selected answer. It hasn’t made a mistake yet, and I don’t expect it to. The only quibble I have with it is stylistic. Given an input such as:

#if (defined(A) && defined(B)) || defined(C) || (defined(D) && defined(E)) 

and run with ‘-UC’ (C is never defined), the output is:

#if defined(A) && defined(B) || defined(D) && defined(E) 

This is technically correct because ‘&&’ binds tighter than ‘||’, but it is an open invitation to confusion. I would much prefer it to include parentheses around the sets of ‘&&’ conditions, as in the original:

#if (defined(A) && defined(B)) || (defined(D) && defined(E)) 

However, given the obscurity of some of the code I have to work with, for that to be the biggest nit-pick is a strong compliment; it is valuable tool to me.


The New Kid on the Block

Having checked the URL for inclusion in the information above, I see that (as predicted) there is an new program called Coan that is the successor to ‘sunifdef’. It is available on SourceForge and has been since January 2010. I’ll be checking it out…further reports later this year, or maybe next year, or sometime, or never.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T04:16:58+00:00Added an answer on May 11, 2026 at 4:16 am

    I know absolutely nothing about C, but it sounds like you are looking for something like unifdef. Note that it hasn’t been updated since 2000, but there is a successor called "Son of unifdef" (sunifdef).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 130k
  • Answers 130k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use :host option in your url. invitation_activation_url(1, :host => "www.xyz.at")… May 12, 2026 at 6:03 am
  • Editorial Team
    Editorial Team added an answer I think this post by the Misfit Geek could help… May 12, 2026 at 6:03 am
  • Editorial Team
    Editorial Team added an answer This code will work for vertical gradient and make it… May 12, 2026 at 6:03 am

Related Questions

Original Question What I'd like is not a standard C pre-processor, but a variation
[Edit] My original-question was Why to decide between static and non-static? Both do the
What is the 'correct' way to store a native pointer inside a Java object?
There are several tabs in GUI runner of NUnit: I understand that using Console.WriteLine
Alex explained what I'm looking for much better than I have: You want an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.