Strange Compilation

amitrane's Avatar, Join Date: Oct 2006
Go4Expert Member
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 claculateVolume(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 shabbir; 30Oct2006 at 18:07.. Reason: Code formating.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by amitrane
1)What is the Error ?
I dont see any error. You have claculateVolume as function prototype and calculateVolume as function body but as you are not calling either.
Quote:
Originally Posted by amitrane
2) Is it Machine Dependent ?
Nope
Quote:
Originally Posted by amitrane
3)Is it version dependent (e.g turboc,gnuc,etc.) ?
Nope
0
amitrane's Avatar, Join Date: Oct 2006
Go4Expert Member
I am still confused.Can u please provide some more help ?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by amitrane
I am still confused.Can u please provide some more help ?
Can you tell me what is the confusion??
0
amitrane's Avatar, Join Date: Oct 2006
Go4Expert Member
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 ?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by amitrane
I am not understanding even though the function prototype is not matching,why no error is reported ?
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

Quote:
Originally Posted by amitrane
Is the "function.h" really making any significant contribution to the program except for function definition ?
.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.
0
amitrane's Avatar, Join Date: Oct 2006
Go4Expert Member
Thank you Sir.