Operating Systems > Linux and UNIX

C Programming from literally thr ground up

(1/4) > >>

Calum:
So, i am literally at the 'hello, world' stage, and my book says that to use printf, i need to declare stdio.h which i understand of course, well i being me, went and did 'less /usr/include/stdio.h' to see what the magical defenitions were that miraculously allowed me to use the printf function, and of course could not understand a word!

What are the headers themselves written in? and since they are text (seemingly) is it possible for some headers be closed source?

I know i should get more into it but you know, always inquisitive. ANd i will be getting more into it anyway, just nosy really!

[ July 14, 2002: Message edited by: Calum ]

TheQuirk:
All of the headers I used are always "open" to view. I'm sure someone else here could give a better answer, because I can't (i'm not sure myself.)

jtpenrod:

quote: /* Define ISO C stdio on top of C++ iostreams.
   Copyright (C) 1991, 1994-1999, 2000, 2001 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */
--- End quote ---
Here is the beginning of stdio.h. As you can see, it most definitely is not closed source. What this file contains are simply the usual C-type forward declarations with some compiler conditionals that may or may not be included, depending upon what system it's being run on and what features it supports. It might seem all a bit arcane right now, but there really isn't anything too out of the ordinary there. Of course, stdio.h itself depends upon three other files: stddef.h, features.h, and bits/types.h.
--- Code: ---
--- End code ---
Here is the part that allows printf to work. This forward declairs a function, printf, that returns an integer to the calling routine. Since it's declaired to be an "extern", the compiler will look in other files for the actual definition and implementation of printf. "__THROW" is a macro for error handling should something go wrong and printf can't execute. Of course, being at the "Hello World!" stage, there's no way you'd be expected to know all this just yet. Keep at it, and all will become clear.
_______________________________________

Live Free or Die: Linux

"There: now you'll never have to look at those dirty Windows anymore"  --  Daffy Duck  :D

voidmain:
stdio.h is C source code. "headers" are really nothing more than prototype declarations for functions contained in libraries (and more). The printf() function is actually contained in /usr/lib/libc.a (static library) and /lib/libc.so.6 (dynamic library). Those libraries are binary (compiled). The benefit you get from linking your code to these libraries is so you don't have to recompile each and every standard function every time you compile a program (saves MUCH time).  If you want to see what the actual "printf()" function code looks like you will have to get the libc source code (there is an RPM for it).  There will probably be a "printf.c" file included in there. "libc" contains most of your basic standard C functions.

Does that help any?

TheQuirk:
what I'm intrested is (it seems to relate to this) if there are headers that we use that AREN'T under the GNU?

Navigation

[0] Message Index

[#] Next page

Go to full version