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 7020675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:20:56+00:00 2026-05-27T23:20:56+00:00

I have a number of debug statements defined in a program, and I want

  • 0

I have a number of debug statements defined in a program, and I want to be able to make a copy of the source without these statements.

In order to do this I first looked at GCC’s -E command line argument, which only runs the preprocessor, however this did far more than I wanted, expanding the included files and adding #line statements.

For example:

#include <stdio.h>

#ifdef DEBUG
    #define debug( s ) puts ( s );
#else
    #define debug( s )
#endif

int main( int argc, char* argv[] )
{
    debug( "Foo" )

    puts( "Hello, World!" );

    return 0;
}

I’d want this to be processed to:

#include <stdio.h>

int main( int argc, char* argv[] )
{


    puts( "Hello, World!" );

    return 0;
}

I could then tidy that up with something like astyle and no manual work would be needed to get exactly what I want.

Is there a directive I’m missing for GCC or is there a tool capable of doing this?

  • 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. Editorial Team
    Editorial Team
    2026-05-27T23:20:57+00:00Added an answer on May 27, 2026 at 11:20 pm

    If -E is not helping, then try using -fdump-tree-all and if you don’t see what you want the that is not-available-in (or) not-provided-by GCC.

    OTOH, this question has been discussed in SO as follows, please refer the below to get some ideas.

    1. Can gcc output C code after preprocessing?
    2. How do I see a C/C++ source file after preprocessing in Visual Studio?

    Hope it helps!


    Hi Mat,

    I saw your comment to @nos. But I have one such script handy and so sharing it with you. You can try reading my answer for a similar question here

    Copy the below code in a file, say convert.sh. Assign execute permission to that file, chmod +x convert.sh and run it as follows:

    $./convert.sh <filename>.c
    $cat filename.c.done
    

    The <filename>.c.done will have what you need!

    #!/bin/bash
    
    if [[ $# -ne 1 || ! -f $1 ]] ; then
        echo "Invalid args / Check file "
        exit 
    fi
    
    file_name=$1
    
    grep '^\s*#\s*include' $file_name > /tmp/include.c
    grep -Pv '^\s*#\s*include\b' $file_name > /tmp/code.c
    gcc -E /tmp/code.c | grep -v ^# > /tmp/preprocessed.c
    cat /tmp/include.c > $file_name.done
    cat /tmp/preprocessed.c >> $file_name.done
    

    Hope this helps!

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

Sidebar

Related Questions

I have a program that monitors debug messages and I have tried using a
I have a number of native C++ libraries (Win32, without MFC) compiling under Visual
I have developed a .net 3.5 c# web application and want to make some
How do i find the count of the number of debug statements that is
I'm working on a project were we have number (5 at the moment) of
I have a number of macros written for Visual Studio 2005, but they have
I have a number of tracks recorded by a GPS, which more formally can
I have a number of application settings (in user scope) for my custom grid
i have a number of jsp files under web-inf folder. Inside my web.xml i
I have a number of data classes representing various entities. Which is better: writing

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.