Hi
Just wondering when writing a 'C' program, that has an #include
directive, is the whole library include in the resultant compiled code or is
only the referanced functions included? for example if I had included the
standard input and output library and only used the 'print' function, would
the compiled code only include the 'print' function?
I hope you meant the printf() function, since there is no standard C
function named "print". Also you don't include libraries, you include
headers and header files.
As to your question, the C language does not specify what might or
might not get included in your program. It is up to your compiler and
tool set, including the linker, and probably the way the compiler's
library was built. So it is really a QOI (Quality Of Implementation)
issue rather than a language issue.
Under some operating systems, such as Windows and various *NIX types,
the default is frequently to use some sort of dynamic linking
mechanism, the details of which are off-topic here. Under such
systems, the code for printf() is not included in your executable at
all, instead there is one copy of all C library functions loaded into
memory and shared by all programs that are running.
Most implementations that perform static linking, which means actually
including the body of library functions into the executable image of
the program, only include those that are needed. But again this is an
implementation issue, not a language one. A compiler that included
the body for every standard library function into every executable
regardless of which functions the program actually called would not be
violating the C language standard.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq