Is stdio.h a library?

No, stdio.h is not a library, it's a header file. A common mistake when approaching C is to call every header file a library, that's just wrong.

The C standard library is a collection of functions, which are declared in header files, and stdio.h is one of them. The name stands for "Standard Input Output", so in that file you can find all the declarations of functions that deal with input, output and files. You can find a list of the header files included in the C standard library here.

A library is a compiled binary file (or in general, a collection of binary files), which can be linked when compiling a program to take advantage of the functions made available by the library (i.e. exported). Header files are then used to identify the names and the signatures of those functions, so that the compiler knows how to call them.

Commonly, for small libraries, a single header file is enough, so that's easy for beginners to confuse an header file with the library itself. The C standard library however is very complex and has a lot of functions, so they are declared in different header files.

C programs start with #include <stdio.h> because the C language does not include file manipulation functions.

Yes, that's right. The C specification only concerns the language itself (syntax, types, etc), and does not define any "standard" function.


My book, "The C Programming Language" calls stdio.h a library. Now, I am being told that it's a "header file" only meant for the compiler, which is true, and therefore it's not a library.

I have a copy of that book (the first edition, and also the ANSI edition), and I don't remember there being any confusion about the difference between a header file and a library. Can you point us to where you're looking? On page 152, for example, I see:

Each source file that refers to an input/output library function must contain the line
#include <stdio.h>

And that's true enough... it's not saying that stdio.h is a library, but rather that you have to include the header file if you want to use the library. Similarly on page 176:

The data structure that describes a file is contained in , which must be included (by #include) in any source file that uses routines from the standard input/output library. It is also included by functions in that library...

In this paragraph that library refers to "the standard input/output library," not stdio.h itself. I could see how someone might misread that, but in context the book really isn't calling stdio.h a library here.

If you can point us to the particular passage that you're looking at, perhaps we can explain better.


Update:

The passage you quote from the book is from the introduction to the second edition, and it's talking about the history of the language up to that point (the second edition came out in 1988). In particular, the paragraph is talking about the C standard library:

A second significant contribution of the standard is the definition of a library to accompany C...

It looks like the part that inspired your question is this:

...Most of the library is closely modeled on the "standard 1/0 library" of the UNIX system. This library was described in the first edition, and has been widely used on other systems as well...

In all cases, when the text says library it really means that, not header file. Every C library has one or more associated header files that provide the interface to the associated library; without the header(s), you (and your compiler) wouldn't know how to access the functions that are defined in the library. For example, the fopen() function is declared in the stdio.h with a function prototype:

FILE *
fopen(const char * restrict path, const char * restrict mode);

Once you have the declaration of fopen() available, the compiler knows how to generate instructions to call that function, and the linker will connect your code to the actual function definition in the library file itself. So when the text says standard I/O library, it's really talking about the library, and the header file of the same name is just an ancillary file that lets you access the library.

It would seem a logical conclusion that the definition of library has evolved/changed/updated...

No, that's not what's happened; header files and libraries are and have always been distinct but related things, and the meaning really hasn't changed since the book was written, at least with respect to C.

Tags:

C

Libraries