include vs. -library

T

Tom Impelluso

Hello,
May I ask for help/advice, please?


There are some C functions that require both a header and a library link:
exp(), sin(): #include<math.h> and -lm

There are some C functions that require JUST a header: malloc(),
fprintf(): #include<stdlib> or stdio.h

There are some C functions that require neither printf()
(actually, printf technically requires the #include, but if I do
not exploit the return value, I do not have to include it to
prototype the function)

Could someone tell me if these functions fall into NAMED categories?
Why was the language created so that there is this apparent asymmetry
in the use of functions: with regard to when to link a library
and when to include?

I understand the NEED to include headers... and libraries... But I am
only searching for why there is this apparent lack of balance....
i.e: What are the categories of these functions in C?

And, as a further example, there is the sleep(); function.
What TYPE of function is that (I know what it does, but why is
there no include and no library at all?)

thanks
t.
 
A

Américo Wang

om Impelluso said:
Hello,
May I ask for help/advice, please?

There are some C functions that require both a header and a library link:
exp(), sin():  #include<math.h> and -lm

There are some C functions that require JUST a header: malloc(),
fprintf():  #include<stdlib> or stdio.h

There are some C functions that require neither printf()
(actually, printf technically requires the #include, but if I do
not exploit the return value, I do not have to include it to
prototype the function)

Could someone tell me if these functions fall into NAMED categories?
Why was the language created so that there is this apparent asymmetry
in the use of functions: with regard to when to link a library
and when to include?

No, you misunderstood.

Any library function will need both a header, where you can find its
declaration,
and a library, where you can find its implementation. *Unless* that
function is
implemented as a macros or a inline function, but you can't assume
this,
this is rare AFAIK.

For fprintf(), printf(), etc., they are in libc library, which will
be probably linked by default by the compiler.
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top