Including header file with in the header file

This is a discussion on Including header file with in the header file within the C Programming forums, part of the General Programming Boards category; Can I include a user written .h file within the .h file in C ???...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    16

    Including header file with in the header file

    Can I include a user written .h file within the .h file in C ???

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    16
    The answer can't fulfil my query.
    Sappose I make a header file named gtool.h and within this .h file I include that gtool.h
    Is that exceptable?

  4. #4
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Why would you want to? No, it's not acceptable. If you include the same file you're currently in, you'll get a loop, and the compiler will error.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    16
    I recently Buy a book named Graphics programing in c by BPB publication.Wher I found a user written file
    named gtools.h and there I see the gtools.h included within the header file.Can u send me a sample user written header file by which i draw both rectangle and circle (as per example)
    I exactly want to know how I right the code. So pls help me with your enormous skill!

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    That was probably a publishing error -- just comment out the recursive include. Many books are netorious for publishing bad, unedited code.

  7. #7
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    but, consider this...
    Code:
    #include "any.h"
    and
    Code:
    #include <any.h>
    are not the same!

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    134
    hello fnoyan...
    As we know for a use defined header file we use to include header file in double quotes like "Header.h" . and inbuilt header in angle brackets, like <Header.h>. But why this difference is there and how compiler treats to both.
    S_ccess is waiting for u. Go Ahead, put u there.

  9. #9
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    Some applicatons you write may need special definitions and you put them into your own header file.On some systems, like UNIX, an ordinary user cannot copy a header file into one of the standart header lookup directories for compiler.

    In most of C++ programs class definitions and implementations are done in different files and included in the main file.

    You can specify your own header include directory for the compiler and may use <anyhile.h> instead of "anyfile.h" even if your header is not in the predefined header include path. For example, if you use gcc you can specify the current directory as a standart include file lookup directory as follows
    Code:
     gcc -L./ prog.c
    I think there is no difference between both type of include from the compiler point of view.

  10. #10
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    gcc uses -I for additional include paths, not -L. -L is for additional library path searches.

  11. #11
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by fnoyan
    but, consider this...
    Code:
    #include "any.h"
    and
    Code:
    #include <any.h>
    are not the same!
    depends on the compiler -- some compilers do not distinguish between quotes and brackets.

  12. #12
    Registered User
    Join Date
    Dec 2005
    Posts
    134

    Question

    Quote Originally Posted by Ancient Dragon
    depends on the compiler -- some compilers do not distinguish between quotes and brackets.
    U are talking about compiler dependent views. But what does the ANSI standard says about these two.
    S_ccess is waiting for u. Go Ahead, put u there.

  13. #13
    Registered User
    Join Date
    Dec 2005
    Posts
    16
    Thank u all. Ur knowledge will help me to spread my idea and depth on c & c++. Thanks for debating on my topic

  14. #14
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    Quote Originally Posted by maven
    U are talking about compiler dependent views. But what does the ANSI standard says about these two.
    From section 6.10.2 of the standard:
    2 A preprocessing directive of the form
    # include <h-char-sequence> new-line
    searches a sequence of implementation-defined places for a header identified uniquely by
    the specified sequence between the < and > delimiters, and causes the replacement of that
    directive by the entire contents of the header. How the places are specified or the header
    identified is implementation-defined.
    3 A preprocessing directive of the form
    # include "q-char-sequence" new-line
    causes the replacement of that directive by the entire contents of the source file identified
    by the specified sequence between the " delimiters. The named source file is searched
    for in an implementation-defined manner. If this search is not supported, or if the search
    fails, the directive is reprocessed as if it read
    # include <h-char-sequence> new-line
    with the identical contained sequence (including > characters, if any) from the original
    directive.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 01:44 PM
  2. Including headers in a header file
    By tjpanda in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2008, 09:48 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Replies: 6
    Last Post: 04-02-2002, 05:46 AM

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