Pre Processor output

This is a discussion on Pre Processor output within the C++ Programming forums, part of the General Programming Boards category; Can any of known compilers output the result of pre pocessor? For example: Code: #define d #ifdef d cout<<"ok"; #else ...

  1. #1
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231

    Question Pre Processor output

    Can any of known compilers output the result of pre pocessor?
    For example:
    Code:
    #define d
    #ifdef d
    cout<<"ok";
    #else 
    cout<<"no";
    #end if
    Result will be

    Code:
    cout<<"ok";
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,703
    Yes, you could run something like this through the pre-compiler:
    Code:
    #define d
    #ifdef d
      #define STR "OK"
    #else
      #define STR ""
    #endif
    
    #include <iostream>
    int main ( ) {
      std::cout << STR;
    }
    $ g++ -E foo.cc > output.txt

    It dumps a whole lot of stuff though, the standard header files are gigantic. You could do something clever to avoid it I suppose.
    Last edited by whiteflags; 08-11-2006 at 04:58 PM.

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    It dumps a whole lot of stuff though, the standard header files are gigantic.
    It is exactly what I want. I want to see all includes in one file.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,703
    Anyway, it would just be a matter of reading your compiler's documentation to find out what switch you need to use and then writing a file that lets you see what you want to see.

  5. #5
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Quote Originally Posted by citizen
    Anyway, it would just be a matter of reading your compiler's documentation to find out what switch you need to use and then writing a file that lets you see what you want to see.
    Yes, it is exactly what I am doing. I didn't find any swtch in IDE options though and I am hopless.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #6
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    I found it. I don't know why I didn't see it before. It is /P in my compiler.
    Thank you.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 03:09 AM
  2. I need to play a pre recorded vox file using C
    By m.sudhakar in forum C Programming
    Replies: 4
    Last Post: 11-17-2006, 05:59 PM
  3. New compiler - Weird errors -,-.
    By Blackroot in forum C++ Programming
    Replies: 8
    Last Post: 08-27-2006, 07:23 AM
  4. Conflicting types of typedef error
    By advocation in forum C++ Programming
    Replies: 4
    Last Post: 03-22-2005, 05:26 PM
  5. Post increment and pre increment help
    By noob2c in forum C++ Programming
    Replies: 5
    Last Post: 08-05-2003, 03:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21