Thread: #include nesting level?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    3

    Question #include nesting level?

    I'm working on a fairly large project, and in an effort to be moderately organized, I'm placing every class, every part, in a seperate .cpp/.h pair. Needless to say, since each part needs several of the others, this leads to a large amount of #Include's.
    I've had no problems with this, until today, when modifying one specific part required the adding of a couple more #includes. Now, I'm suddenly getting a bunch of the following errors:

    warning C4182: #include nesting level is 362 deep; possible infinite recursion

    and

    fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit

    Is there a limit to the number of #includes that can be used in any given project? What is this internal heap limit, and is this /Zm?

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    You have a header file which includes a header file which includes the
    first header file.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    The best way around that is put conditional defines in your .h files :

    Code:
    #ifdef __HFILENAME__  //or some unique name to the .h file
    #define __HFILENAME__
    
    all you .h stuff....
    
    
    #endif
    What happens on the first time this .h file is included __HFILENAME__ is not defined so it defines it and includes everything from there until the #endif. The next time this file is included __HFILENAME__ is defined so that code is ignored. This will keep your .h files from running over each other.

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, 01:53 PM
  2. debug assertion failed!
    By chintugavali in forum C Programming
    Replies: 4
    Last Post: 12-11-2007, 06:23 AM
  3. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10:08 PM
  4. Weird, cards not outputting correctly
    By Shamino in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2007, 03:26 PM
  5. Read and write hanging
    By zee in forum C Programming
    Replies: 8
    Last Post: 08-03-2004, 11:19 PM