Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Strange Compilation (http://www.go4expert.com/forums/strange-compilation-t1755/)

amitrane 30Oct2006 17:47

Strange Compilation
 
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.

shabbir 30Oct2006 18:10

Re: Strange Compilation
 
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

amitrane 30Oct2006 18:27

Re: Strange Compilation
 
I am still confused.Can u please provide some more help ?

shabbir 30Oct2006 18:29

Re: Strange Compilation
 
Quote:

Originally Posted by amitrane
I am still confused.Can u please provide some more help ?

Can you tell me what is the confusion??

amitrane 30Oct2006 18:35

Re: Strange Compilation
 
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 ?

shabbir 30Oct2006 19:31

Re: Strange Compilation
 
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.

amitrane 31Oct2006 13:27

Re: Strange Compilation
 
Thank you Sir.


All times are GMT +5.5. The time now is 16:28.