[comp.lang.c] C error which worked fine

ssreefc@techunix.BITNET (florin coter) (02/09/89)

hello world.
i wrote the following WRONG code:
..
        FILE *open(), *fp;
        int close();

        fp = fopen(...);
        fprintf( fp, ...);
        fclose(fp);
..
i used turboc 1.5. all went fine (no error note), untill i read the error.
the undeclared fopen sould have been assumed of type int and not FILE *...
so why did it work ok?
thanks, florin.

henry@utzoo.uucp (Henry Spencer) (02/10/89)

In article <7631@techunix.BITNET> ssreefc@techunix.BITNET (florin coter) writes:
>the undeclared fopen sould have been assumed of type int and not FILE *...
>so why did it work ok?

First, are you sure you didn't include <stdio.h>, which declares those things?
Second, in many (not all!) C implementations, pointers and ints are the
same size and are handled much the same way, so you can sometimes get
away with lying to the compiler about the type of returned values, because
it treats them the same way regardless.
-- 
The Earth is our mother;       |     Henry Spencer at U of Toronto Zoology
our nine months are up.        | uunet!attcan!utzoo!henry henry@zoo.toronto.edu