newbie question

N

Neil Morris

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?
 
K

Kevin Goodsell

Neil said:
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?

#include directives do not include libraries. They usually include
header files which usually only declare functions, variables, etc. A
corresponding library sometimes has to be linked in, but this is the
linker's job, not the compiler's.
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?

Implementation-dependent.

-Kevin
 
J

Jack Klein

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
 
N

Neil Morris

PS Also if I wanted a stand alone program ie ported to another computer were
the resultant compiled code is self contained as in handheld devices, were
memory is at a premium. Are there compiler options for this sort of output
were the compiled code creates its own operating environment?
 
M

Morris Dovey

Neil said:
PS Also if I wanted a stand alone program ie ported to another computer were
the resultant compiled code is self contained as in handheld devices, were
memory is at a premium. Are there compiler options for this sort of output
were the compiled code creates its own operating environment?

Neil...

Probably (almost certainly) not.

It's an interesting thought though. Such a compiler/library could
turn my 'hello.c' source into 'hello' plus (presumably the latest
version) unix for my cable modem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top