1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Strange Compilation

Discussion in 'C' started by amitrane, Oct 30, 2006.

  1. amitrane

    amitrane New Member

    Joined:
    Oct 21, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Studying
    Location:
    Navi Mumbai
    I have these 3 code files in C.

    My problem is that even though the function name is typed wrongly the program is still compiling.I am using GNUC.

    Here are the 3 files.

    The Error is Highlighted.

    main.c

    Code:
    #include <stdio.h>
    #include "functions.h"
    
    
    int main() {
    	int j, num;
    	float radius[50], height[50];
    	
    	scanf("%d", &num);
    
    	for( j = 0; j < num; j++) {
    		scanf("%f%f", &radius[j], &height[j]);
    	}	
    
    	for ( j = 0; j < num; j++ ) {
    		if ( testContainer(radius[j], height[j]) )
    			printf("Container radius: %f, height: %f\n", radius[j], height[j]);
    	}
    	return 0;
    }
    function.c

    Code:
    #include <stdio.h>
    #include "functions.h"
    
    float calculateVolume(float r, float h) 
        {
    	return 3.142 * r * r * h;
        }
    
    int testContainer(float r, float h) 
      {
    	if ( 500 <= calculateVolume(r, h) ) 
    		return 1;
    	return 0;
      }
    functions.h
    Code:
    #ifndef FUNCTION_H
    #define FUNCTION_H
    
    float [B][COLOR=DarkRed]claculate[/COLOR][/B]Volume(float r, float h);
    int testContainer(float r, float h);
    
    #endif
    My questions are ?

    1)What is the Error ?
    2) Is it Machine Dependent ?
    3)Is it version dependent (e.g turboc,gnuc,etc.) ?

    Thanking you.
     
    Last edited by a moderator: Oct 30, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    I dont see any error. You have claculateVolume as function prototype and calculateVolume as function body but as you are not calling either.
    Nope
    Nope
     
  3. amitrane

    amitrane New Member

    Joined:
    Oct 21, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Studying
    Location:
    Navi Mumbai
    I am still confused.Can u please provide some more help ?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Can you tell me what is the confusion??
     
  5. amitrane

    amitrane New Member

    Joined:
    Oct 21, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Studying
    Location:
    Navi Mumbai
    Sure Sir.

    I am not understanding even though the function prototype is not matching,why no error is reported ?

    Is the "function.h" really making any significant contribution to the program except for function definition ?
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    There isnt any error because you are trying to make a call to them. Say you have 10 such functions defined but if you dont call them there is not any error that can be reported.

    If you call either of them you will likely to get an error.

    If you call the one in .c file you will get the error its not defined

    If you call the .h one you will get function body not defined error

    .h files are meant for providing an interface to the cpp file which have the actual function which is what is tried in the above problem.
     
  7. amitrane

    amitrane New Member

    Joined:
    Oct 21, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Studying
    Location:
    Navi Mumbai
    Thank you Sir.
     

Share This Page