C header file question?

This is a discussion on C header file question? within the C Programming forums, part of the General Programming Boards category; Hello, I have a question. I read that C header files can be incluided more than once, with the effect ...

  1. #1
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Lightbulb C header file question?

    Hello,
    I have a question. I read that C header files can be incluided more than once, with the effect being the same as if they were included only once, is that correct? Now why would anyone want to be redundant? Thats my ?


  2. #2
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    to make a C header file so that it can be #include'd more than once but will only be #include'd once, do something like this

    foobar.h:
    Code:
    #ifndef FOOBAR_HEADER_FILE
    #define FOOBAR_HEADER_FILE
    
    // put your header code here, then right before the end of file:
    
    #endif
    why? because header files sometimes include other header files, for various reasons, and especially when you get into a large many filed program, this method stops "circular dependancies" from occurning where

    foo.h includes bar.h
    bar.h includes kensmom.h
    kensmom.h includes foo.h

    with this (very standard btw) method,

    foo.h includes bar.h
    bar.h includes kensmom.h
    kensmom.h says to include foo.h, but the preprocessor looks and see's that foo.h has already been included, so it doesnt include it again.
    hello, internet!

  3. #3
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Smile stops "circular dependancies" from occurning

    oh!
    Thanks, i'll remember that.

  4. #4
    Unregistered
    Guest
    It takes less effort to slap it in, whether it's needed or not. That's why they sometimes get included more than once.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 11:39 PM
  2. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 11:51 PM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 09:19 PM
  4. header file question
    By unanimous in forum C Programming
    Replies: 1
    Last Post: 12-15-2001, 08:15 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

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