12

I sometimes see these two terms be used interchangeably.

What is the actual difference between these two terms? How are they used differently? Are there any other alternatives to these two libraries?

1
  • 7
    I assume you have performed an online search before asking here. What did you find so far? How does that information not answer your question? Please edit the question to show your effort, so that the answers don't have to repeat something you already know. See also: How do I ask a good question?
    – amon
    Oct 23, 2017 at 12:03

3 Answers 3

32

The C standard library is part of the C programming language, so it is a specification (written in English in some technical report). For example, the n1570 document is explaining what is malloc and how it should behave.

There is also another relevant specification, the C POSIX library (which is more or less a superset of the C standard library). For example both dlopen and fork are specified by POSIX (but ignored by the C11 standard).

The GNU glibc library is an implementation of (a superset of) the C standard library and of the C POSIX library. It is some free software (mostly written in C for the GCC dialect with a bit of assembler). It uses system calls (listed in syscalls(2)) processed by the kernel. You could use some other implementation of the C standard library, like musl-libc (or dietlibc).

You could avoid any libc and make direct system calls to the kernel by writing assembler code. This is rarely done (an example is the Bones Scheme compiler, or BusyBox). Most programs do system calls thru the libc and take advantage of functions provided by that libc. Hence libc is a corner stone of Linux systems...

By the way, the GNU glibc has useful functions outside of the standard, such as backtrace functions, or some additional ways to parse program arguments.

Notice that there are subtle differences between what the standard requires and what happens in practice (for example, memory overcommitment affects malloc in a non-standard way, or Linux dlopen has more flags than what POSIX requires).

Th man pages on Linux in general explain how standard conforming is a function. Look for example in dlopen(3).

See also libc(7) and vdso(7).

2

If you read "UNIX" for "GNU", for a long time the terms were interchangeable because they were the same thing.

Until BSD got off the ground, AT&T's UNIX library was THE C library -- because their compiler was THE C compiler (for the most part).

After BSD, then you had System V UNIX, BSD UNIX, GNU (GNU's Not Unix), and pretty soon there were C compilers everywhere, each with their own implementation of the standard library.

1

Every implementation of C has to supply the standard library, but not every C compiler is written by the FSF! So the GNU C compiler will use the GNU C library, and Intel's C compiler uses a different standard library (with a less catchy name). Both will be instantiations of the standard library that the C standard requires.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.