Thread: Pre Processor output

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

    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
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    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,246
    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
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    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,246
    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,246
    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, 04: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, 06: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, 06: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