-2

From bruce eckel --" although u should always declare functions by including header file , functions declarations aren't' essential in c . Its possible in c but not cpp to call a function u havent declared. This is a dangerous practise because the c compiler may assume that a function that u call with an integer argument has an argument list containing integer even if it may actually contain float . This can produce bugs" my question is that even if a function is not declared , during its definition we have to mention the data type of arguments [ VOID FUNC( INT A)] , so how can a compiler assumes a float to be an integer??

sumit
  • 87
  • 1
  • 7
  • Suppose the compiler sees `foo(8)`. Should it assume foo takes an integer, or a float? If you expect all writers of software to be careful enough to write `foo(8.0)`, you have a rude awakening coming. – William Pursell Dec 13 '14 at 23:44

1 Answers1

1

The compiler makes assumption on supplied parameters if a function is not declared or defined prior to the point the assumption should be made. Try the following code and check the result (checked with gcc):

#include <stdio.h>

int main (int argc, char * argv[])
{
        x(1);
        x(1.);
        x(1);
        return 0;
}

void x(double y)
{
    printf ("%f\n", y);
}
loshad vtapkah
  • 429
  • 4
  • 11