Joona I Palaste wrote:
candy <ca********@yahoo.com> scribbled the following:
hi all,
I just want to know that whether the C header files( like stdio.h,etc
which the compiler provides) just contains the function declarations
That's right, except that they may also contain type declarations and
#defines.
or they also contain some additionalinformation like where to look in
the memory for the defintions of the standard functions like
scanf(char*c,...)).
No. The C language does not define any such facility.
Joona is correct when he says the C language as such
has no way to place a particular function at a particular
memory location. However, each implementation of C uses
some amount of "implementation magic" outside the realm of
C itself, and it is at least conceivable that some "magic"
in some implementation might locate its library functions
this way. It would certainly be an unusual approach, but
it's within the realm of possibility. Systems have used
things like "jump tables" or "branch vectors" before, and
perhaps some might still use the technique for C.
Also,if there is no information about the location of the memory where
the definitions of the standard functions is present,then can we just
declare the function which we want to use,ourselves,and then don't
include the required header file/s.
That is correct. All the compiler and linker care about is getting the
needed declarations correctly. They don't care where they come from.
Joona is right again, but some library functions cannot
be declared "free-hand" because there's no way to write their
prototypes without using the contents of the relevant headers.
Take fprintf(), for example: you could write
int fprintf(FILE*, const char*, ...);
easily enough, but you need to have `FILE' declared before
you can do this. The *only* correct way to declare `FILE'
is to include <stdio.h> (because the details of `FILE' vary
from one implementation to another), and since <stdio.h> also
declares fprintf() there's little reason to add your own,
redundant declaration.
Another example: you could write
size_t strlen(const char*);
but where is `size_t' declared? It turns out that many of
the standard header files declare `size_t', and that you could
in fact obtain its declaration by including <stdio.h> or
<stddef.h> or a few others, without including <string.h>.
But the fact that something *can* be done doesn't mean that
it *should* be done; in this case it doesn't even save you
any keystrokes to write a "free-hand" declaration.
--
Er*********@sun.com