[Courses] C Programming For Absolute Beginners, Lesson 1: Setting Up, First Program
Kathryn Hogg
kjh at flyballdogs.com
Mon Feb 6 02:37:56 UTC 2012
On 2012-02-05 20:28, jim wrote:
> You end your response with "all the best". All the best,
> indeed; I've never read such good stuff; big thanks!
> A few questions and surmises:
> * How to configure things so that the #include < > point
> to some other directory?
One simple way is to use -I$directory directives on your command line:
e.g gcc -I/usr/local/include will add /usr/local/include to the front
of the include.
> * Using vi I search for ld-linux.so.2 or libc.so.2 and find
> neither. Searching for #include I find libio.h
> bits/stdio_lim.h bits/sys_errlist.h
> Searching libio.h for #include yields _G_config.h but
> neither libc nor ld-linux.
You can use the ldd command to list the shared libraries that a program
needs at run time.
> Searching _G_config.h for #include yields bits/types.h
> stddef.h wchar.h but neither libc nor ld-linux.
> I give up. I assume puts and getchar are names of functions
> in libc and somehow the #include <stdio.h> directive
> specifies a way for the compiler to extract from libc the
> code for both puts and getchar. (Also, there's the matter
> of resolving a call to printf to be a call to the less
> expensive puts--for the reason that there is only one
> argument to printf in the source code.)
yes, in C you declare a function with an extern statement. When you
run "man puts", the synopsis has the
#include <stdio.h> so you know that in order to use puts(), you need
to include <stdio.h>
So somewhere in stdio.h or another header file included by stdio.h you
will encounter a statement similar to
extern int puts(const char *s);
This *declares* puts to be function returning int that takes a single
string parameter.
Include files are free to #include other files so if you ran "grep puts
/usr/include/stdio.h" you may not actually find the definition in there.
> * what's an "anchor"? something in the stdio.h file or in
> the libc library or in some particular function in libc?
>
--
Kathryn Hogg
http://womensfooty.com
More information about the Courses
mailing list