internal heap limit

This is a discussion on internal heap limit within the C Programming forums, part of the General Programming Boards category; I know it has something to do with how included my files. Here is the exact error that i get. ...

  1. #1
    Unregistered
    Guest

    internal heap limit

    I know it has something to do with how included my files. Here is the exact error that i get.

    c:\program files\microsoft visual studio\myprojects\areacalc\functions.c(1) : warning C4182: #include nesting level is 363 deep; possible infinite recursion
    c:\program files\microsoft visual studio\myprojects\areacalc\functions.c(1) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit

    here is how i have it. I have a main.c with the main function in it. I have these included:
    #include "functions.c"
    #include "header.h"
    #include <stdio.h>
    #include <stdlib.h>

    and in functions.c i have these:
    #include "main.c"
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include "header.h"

    can somebody plz explain this to me in easy terms, cuz i am sort of a noob. It is homework for me. Ive already made the program and it works, when i have it in one file, but my instructure want a header file, a function.c file, and a main.c file, and we havent learned that yet. I am just trying to get ahead on my homework, and i ran into this.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    here is how i have it. I have a main.c with the main function in it. I have these included:
    #include "functions.c"

    and in functions.c i have these:
    #include "main.c"
    Think about it. File1 is including File2, which includes File1, which includes File2, which includes File 1, which includes...

    Furthermore, why are you including ".c" files? Shouldn't these be ".h" files?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77
    ...yes...you shouldn't be including *.c files...and more so...i would arrange them such that

    #include <stdio.h>
    #include <stdlib.h>
    #include "header.h"

    include all of your standard files first...then include the files which you have created...but don't include *.c files....just make those functions into another header file.........

  4. #4
    Unregistered
    Guest
    ok this is what i have in main.c

    /******************************************
    Program: Name: Area Calculator
    Purpose: Calculates the area of various geomatrical shapes
    Input: Keyboard
    Output: Screen
    *******************************************/
    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
    int Square();
    int Rectangle();
    int Parellelogram();
    int Trapezoid();
    int Triangle();
    int Circle();
    int Hexagon();

    int menu_choice;
    printf("\nWelcome to the Area Calculator\n");
    printf("Which shape would you like to calculate the area for: \n");

    printf("1) Square \n");
    printf("2) Rectangle \n");
    printf("3) Parellelogram \n");
    printf("4) Trapezoid \n");
    printf("5) Triangle \n");
    printf("6) Circle \n");
    printf("7) Hexagon \n");
    printf("8) Quit \n");

    printf("Please Choose one: ");
    scanf("%d", & menu_choice);

    if (menu_choice == 1)
    {
    Square();
    }
    if (menu_choice == 2)
    {
    Rectangle();
    }
    if (menu_choice == 3)
    {
    Parellelogram();
    }
    if (menu_choice == 4)
    {
    Trapezoid();
    }
    if (menu_choice == 5)
    {
    Triangle();
    }
    if (menu_choice == 6)
    {
    Circle();
    }
    if (menu_choice == 7)
    {
    Hexagon();
    }
    if (menu_choice == 8)
    {
    return(0);
    }
    if (menu_choice > 8 || menu_choice < 1)// if the menu choice is > 8 or < 1 there is no choice
    {
    printf("Sorry there is no menu choice for that. \n");
    main();
    }
    return 0;
    }

    this is what i have in functions.c

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>

    /******************************************
    Function Name: Square()
    Purpose: Calculates the area of a square
    *******************************************/
    int Square()

    {

    int area_answer;
    int sqside;

    printf("\nEnter the length of the side of the square: ");
    scanf("%d", & sqside);
    area_answer = sqside * sqside; //sqside * itself equals answer
    printf("\nArea: %d\n",area_answer);
    if (sqside < 0)
    {
    printf("The side has to be greater than 0 \n");
    }
    if(area_answer == area_answer)
    {
    main();
    }
    return 0;
    }

    /******************************************
    Function Name: Rectangle()
    Purpose: Calculates the area of a rectangle
    *******************************************/

    int Rectangle()
    {

    int area_answer;
    int rewidth;
    int reheight;

    printf("\nEnter the width of the rectangle: ");
    scanf("%d", & rewidth);
    printf("\nEnter the length of the rectangle: ");
    scanf("%d", & reheight);
    area_answer = rewidth * reheight; //width * height equals answer
    printf("\nArea: %d\n", area_answer);
    if (rewidth < 0 || reheight < 0)
    {
    printf("The width and height have to be greater than 0 \n");
    }
    if(area_answer == area_answer)
    {
    main();
    }
    return 0;
    }

    /******************************************
    Function Name: Parellelogram()
    Purpose: Calculates the area of a parallelogram
    *******************************************/

    int Parellelogram()
    {

    int area_answer;
    int pawidth;
    int paheight;

    printf("\nEnter the width of the parellelogram: ");
    scanf("%d", & pawidth);
    printf("\nEnter the length of the parellelogram: ");
    scanf("%d", & paheight);
    area_answer = pawidth * paheight; //width * height equals answer
    printf("\nArea: %d\n", area_answer);

    if (pawidth < 0 || paheight < 0)
    {
    printf("The width and height have to be greater than 0 \n");
    }
    if(area_answer == area_answer)
    {
    main();
    }

    return 0;
    }

    /******************************************
    Function Name: Trapezoid()
    Purpose: Calculates the area of a trapezoid
    *******************************************/

    int Trapezoid()
    {

    int area_answer;
    int trtwidth;
    int trbwidth;
    int trheight;

    printf("\nEnter the top width of the trapezoid: ");
    scanf("%d", & trtwidth);
    printf("\nEnter the bottom width of the trapezoid: ");
    scanf("%d", & trbwidth);
    printf("\nEnter the height of the trapezoid: ");
    scanf("%d", & trheight);
    area_answer = trheight * (trtwidth + trbwidth) / 2;
    printf("\nArea: %d\n", area_answer);

    if (trtwidth < 0 || trbwidth < 0 || trheight < 0)
    {
    printf("The width and height have to be greater than 0 \n");
    }
    if(area_answer == area_answer)
    {
    main();
    }

    return 0;
    }

    /******************************************
    Function Name: Triangle()
    Purpose: Calculates the area of a triangle
    *******************************************/

    int Triangle()
    {

    int area_answer;
    int triwidth;
    int triheight;

    printf("\nEnter the width of the triangle: ");
    scanf("%d", & triwidth);
    printf("\nEnter the height of the triangle: ");
    scanf("%d", & triheight);
    area_answer = triwidth * triheight / 2;
    printf("\nArea: %d\n", area_answer);

    if (triwidth < 0 || triheight < 0)
    {
    printf("The width and height have to be greater than 0 \n");
    }
    if(area_answer == area_answer)
    {
    main();
    }

    return 0;
    }

    /******************************************
    Function Name: Circle()
    Purpose: Calculates the area of a square
    *******************************************/
    int Circle()

    {
    double pi = 3.141592;
    double area_answer;
    double radius;

    printf("\nEnter the radius of the circle: ");
    scanf("%d", & radius);
    area_answer = pi * (radius * radius); //radius * 2 * pi equals answer
    printf("\nArea: %d\n",area_answer);
    if (radius < 0)
    {
    printf("The radius has to be greater than 0 \n");
    }
    if(area_answer == area_answer)
    {
    main();
    }
    return 0;
    }

    /******************************************
    Function Name: Hexagon()
    Purpose: Calculates the area of a square
    *******************************************/
    int Hexagon()

    {
    double area_answer;
    int side_length;

    printf("\nEnter the side length of the hexagon: ");
    scanf("%d", & side_length);
    area_answer = (3/2) * (side_length * side_length) * sqrt(3);
    printf("\nArea: %d\n",area_answer);
    if (side_length < 0)
    {
    printf("The radius has to be greater than 0 \n");
    }
    if(area_answer == area_answer)
    {
    main();
    }

    return 0;
    }

    how do i get the main.c to know that the functions are located in functions.c then.

  5. #5
    Unregistered
    Guest
    oh, and is this right for the header file?

    /***********************************************
    The Square function. Outputs the area of a square.
    ***********************************************/
    Square(int sqside, int area_answer int main);

  6. #6
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77
    well....why have you named that a *.c file? there is no main function...it's all functions that you have wrote...why is it a *.c file..... Why don't you just drop the #include, and write the actual functions in the program instead of attempting to include them?

    Also........there is an easier way than using so many if statements to check to see what they want the area of...it's called a switch statement....

    Code:
    switch(menu_choice)  {
         
         case 1:   Square();
         case 2:   Rectangle();
         case 3:   Parallelogram();
         
         default:  
             printf("Invalid Selection.");
    better coding if you use a switch statement....if they press 1, Square runs, if they press 2, Rectangle runs, etc etc.....default is what is displayed if none of your selections are requested..

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Don't forget the breaks

    Code:
    switch(menu_choice)  {
    case 1:   Square();
    break;
    case 2:   Rectangle();
    break;
    case 3:   Parallelogram();
    break;
    default:  
    break;
    }
    as the case of an item will continue till it hits a break
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    SavesTheDay wrote:
    well....why have you named that a *.c file? there is no main function...it's all functions that you have wrote...why is it a *.c file..... Why don't you just drop the #include, and write the actual functions in the program instead of attempting to include them?
    There is nothing wrong with the file being a "c" file. Header files are supposed to contain declarations of structures and variables and what not while "c" files contain the code/implementation. For large projects it is good to seperate code into multiple "c" files that contain related code. All that would be needed is to include the functions.c file in the project in order to compile it and link it with the code in main.c. How to do this, the steps involved, depends on the compiler.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  9. #9
    Sayeh
    Guest
    I guess I'm a tad confused as to why you would throw your prototypes into the middle of your main() function...


    Code:
    int main() 
       { 
       int Square(); 
       int Rectangle(); 
       int Parellelogram(); 
       int Trapezoid(); 
       int Triangle(); 
       int Circle(); 
       int Hexagon(); 
    
       ...
    This really isn't the right way to do it. spreading forward declarations out into your code is, well, *sloppy*, and will cause debugging headaches in the future.

    And yes, you've created a "circular" reference by including files that include themselves.

    You can include .c files, it's just that it is a bad practice. Instead of including the .c file, you should create a header with external references for that file (a .h file), and include it instead.

    Inside your include files, to be sure things are only included once, try this:

    Code:
    /*****
     *
     *   MY INCLUDE FILE
     *
     *****/
    
    #ifndef  __Includes.h__
    #define __Includes.h__
    
    
    ....    /* put external references here */
    
    
    #endif  __Includes.h__

    Hope this helps,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Heap Limit?
    By Padawan in forum C++ Programming
    Replies: 8
    Last Post: 04-11-2004, 07:11 PM
  2. Heap limit error???
    By sunburnbyRA in forum C++ Programming
    Replies: 6
    Last Post: 04-10-2003, 03:12 PM
  3. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 03-31-2003, 11:23 PM
  4. heap question
    By mackol in forum C Programming
    Replies: 1
    Last Post: 11-30-2002, 04:03 AM
  5. heap limit
    By bob20 in forum C++ Programming
    Replies: 6
    Last Post: 04-17-2002, 06:48 AM

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