What symbols are defined when you include a file?

This is a discussion on What symbols are defined when you include a file? within the C++ Programming forums, part of the General Programming Boards category; I'm making a small library which will load and display DIB's. In my .cpp file, I need to include some ...

  1. #1
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    What symbols are defined when you include a file?

    I'm making a small library which will load and display DIB's. In my .cpp file, I need to include some files (ctype.h and fstream.h) but, how do I know if they're already included? Or does the header file make sure it's not defined twice?

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    Code:
     #ifndef CTYPE_H
     #define CTYPE_H
    
     {
           .......your code goes here..
    
    
      }
    
     #endif

    this translates to: " if ctype.h is not defined yet in the working program , then define it (write it in).......and finishes the if statement at the end with #endif........

    that's all

    Good Luck

    matheo917

  3. #3
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    All the standard headers should have multiple inclusion guards. If you're making a pre-compiled library I don't think it would matter anyway, as the files would be part of separate translation units.

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    21
    No, but you can do that using preprocessor statements like
    Code:
    //This prevents const.h to be twice included
    #ifndef _CONST_H_INCLUDED
    #include <const.h>
    #endif

  5. #5
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Ahh, so it's just an underscore for the . in the filename? Great. Thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with function call
    By NeMewSys in forum C++ Programming
    Replies: 16
    Last Post: 05-22-2008, 02:53 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. to #include or not to #include
    By krygen in forum C++ Programming
    Replies: 9
    Last Post: 12-25-2004, 12:06 AM
  5. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 05:25 AM

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