[Courses] C Programming For Absolute Beginners, Lesson 1: Setting Up, First Program
jim
jim at well.com
Sun Feb 5 23:49:36 UTC 2012
(maybe not in scope for an intro hello world example,
but might be interesting for discussion anyway...?)
I took a look at the stdio.h file:
ls -l /usr/include/stdio.h # on my system that's 31KB
wc -l /usr/include/stdio.h # on my system that's 920 lines of text
less /usr/include/stdio.h # that's a lot of C code
Note that the #include preprocessor directive seems to take
<stdio.h>
as an argument.
The < > angle bracket characters have a special meaning:
/usr/include/
The #include preprocessor directive opens the file and pastes
its entire contents into the C program at that location. This
means what the compiler compiles is not only the code but all of
the code in the stdio.h file, yes?
How does one "look up the spec" for stdio.h?
A look at my working directory:
ls -l
-rwxr-xr-x 1 jim jim 7180 2012-02-05 15:18 welcome
-rw-r--r-- 1 jim jim 108 2012-02-05 15:18 welcome.c
---------------------^^^^---------------------------
The welcome.c source code is 108 bytes, but the welcome
binary program is 7180 bytes.
Wait a minute. The stdio.h file is 31KB, a lot bigger.
What's going on?
$ strings welcome
strings lchix
/lib/ld-linux.so.2
__gmon_start__
libc.so.6
_IO_stdin_used
puts
getchar
__libc_start_main
GLIBC_2.0
PTRh0
[^_]
Hello, and welcome to the Beginning C Course!
There are not many strings in the welcome binary file.
How'd the welcome binary file get to be over 7KB but not
have hardly any of the stdio.h file contents?
And what's up with the Martian (like [^_] and /lib/ld-linux.so.2
and __gmon_start__ and _IO_stdin_used and PTRh0 and so on)?
How come one of strings is
puts?
I used the printf() function, not the puts() function.
I'm betting that libc.so.6 stores the binary code for printf
and puts and getchar on other stdio.h functions, yes?
What's __libc_start_main about? And GLIBC_2.0 ?
And how come the "Hello, and welcome tothe Beginning C Course!"
is on the very bottom?
with thanks
On Sun, 2012-02-05 at 13:43 -0900, Christopher Howard wrote:
> On 02/04/2012 11:56 PM, Carla Schroder wrote:
>
> >
> > 2. Look up the spec for stdio.h, and see what the various macros and functions
> > in the spec look like in your own stdio.h file.
> >
>
> For those of you who really are beginners, stdio.h is usually located at
> /usr/include/stdio.h. There is also a stdio.h man page.
>
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses
More information about the Courses
mailing list