Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C - What are C implementations?

Could you give me an explanation of what exactly an implementation is, taking inspiration from the three highlighted expressions?

From "C Primer Plus" > Language Standards

Currently, many C implementations are available. Ideally, when you write a C program, it should work the same on any implementation, providing it doesn’t use machine-specific programming. For this to be true in practice, different implementations need to conform to a recognized standard.

like image 837
AlexQualcosa Avatar asked Apr 15 '19 14:04

AlexQualcosa


2 Answers

A standard conforming C implementation consists of a compiler that translates compilation units as mandated by the standard, an implementation of the standard library for all functions required by the standard and something (normally a linker) that puts everything together to build an executable file. In fact the implementation also includes all the software required to then run the produced executable.

We commonly speak of compilers (gcc, clang, msvc) when we should speak of C development environment. And inside each vendor system, you may have different implementations, because for example gcc or clang can generate executables for different int sizes (32 or 64 bits) and eventually different endiannesses. Each configuration then constitutes a specific implementation.

To be more exhaustive, it should be noted that support the standard library may be optional in so called standalone execution environment (by opposition to hosted execution environment). In real world, standalone mode is used for kernel development, because the kernel must be able to start before all the functions from the standard library are available. Else we would have a chicken and egg problem if the kernel required functions that it only can provide when it is fully loaded...


References: The draft n1570 for C11 defines an implementation as:

3.12 implementation:
particular set of software, running in a particular translation environment under particular control options, that performs translation of programs for, and supports execution of functions in, a particular execution environment

like image 135
Serge Ballesta Avatar answered Oct 17 '22 02:10

Serge Ballesta


C is typically implemented by a C compiler. In that paragraph you could simply replace this accordingly.

A reason for the more generic term "implementation" is that a compiler might contain multiple frontends or be made out of different tasks, or there are theoretically other forms than a compiler thinkable.

The C standard is defined against a "abstract machine" which behaves as the standard describes but doesn't have any other requirements and defines mapping to real machines as exercise for the implementor.

like image 34
johannes Avatar answered Oct 17 '22 01:10

johannes