Thread: What parts are there to the C language?

  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    132

    What parts are there to the C language?

    I recalled making a multithreaded program but forgot if I used C or C++. When I google searched if C is multi-threaded I came across this stackoverflow post.

    "C is not intrinsically a multithreaded language; however there are many libraries which add threading functionality."

    I don't understand because <math.h> is a library, so does that mean C doesn't intrinsically have a function for raising a number to the power of another?

    When I did multithreading with a program written in C we used pthreads. I know pthreads are supplied by the operating system. I guess my question is where is <math.h> supplied, is it already known by all C compilers?

    If something is part of the C standard library does that mean any C compiler must support it?

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    If something is part of the C standard library does that mean any C compiler must support it?
    Yes, with a few caveats: some things are optional (e.g. variable length arrays in C11), and there are two "types" of implementation, freestanding and hosted. Freestanding implementations need not implement the full standard library, and are primarily intended to target embedded systems.

    For some terminology: math.h is not a library, it's a header. Headers are typically used for declarations, so they'll provide function prototypes, type definitions, macros, and so on. So math.h tells the compiler what the pow() function looks like, for example, and a system-specific library/implementation actually provides pow() (such as libc or libm on Unix systems).

    Standard C is logically split into two parts: the language and the library. The language defines the syntax of C, basically, and the library implements useful functions. Both are part of standard C, but are often distributed separately, such as the Clang compiler and FreeBSD C library on FreeBSD, or the GNU C compiler and GNU C library on many Linux systems.

    As to the question of whether C intrinsically has a function for exponentiation: it does, because the C standard defines the pow() and related functions, so they're part of C. Now, you could argue that the C language does not contain such functionality, because it's provided by the standard library, but that's not a particularly useful distinction.

    As for where math.h comes from, it depends on your implementation. On Linux, it's probably provided by glibc, which is the library; the C compiler does not provide it. But again, this is a somewhat unnecessary distinction in general: to be correct you'd probably want to say that your C implementation provides math.h but if you say it comes with the compiler, that's technically wrong in some cases (for example, neither gcc nor clang provides math.h), but who cares? The term "compiler", if you're just speaking casually, is somewhat like "Linux"; it's technically just one part of the system, but is often used to refer to the whole. Anyhow, there's nothing preventing a compiler from implementing the whole library itself, and many compilers do implement part of the library, for performance reasons.

    As for threading: just because the C standard doesn't provide a particular piece of functionality, that doesn't mean such functionality cannot be provided as an extension, or by a third party. So you can have pthread.h, defined by POSIX, and math.h, defined by the C standard, living side-by-side, potentially even implemented in the same library. An in fact, the latest C standard does include threading, but I doubt support is too widespread yet.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Explain this c language code....only 2 parts of it?
    By ankit8946 in forum C Programming
    Replies: 22
    Last Post: 10-31-2009, 03:33 PM
  2. array parts
    By taurus in forum C Programming
    Replies: 18
    Last Post: 10-06-2007, 12:21 AM
  3. What's the Difference Between a Programming Language and a Scripting Language?
    By Krak in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 07-15-2005, 04:46 PM
  4. String Parts
    By (TNT) in forum Windows Programming
    Replies: 2
    Last Post: 07-28-2002, 08:19 PM
  5. Algorithms in C Parts 1-4
    By emperor in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 03-09-2002, 08:57 PM