3

I often see the statement "implementation-defined" in the C Standard documentations, as well as getting it as answer very much.

I have then searched in the C99 Standard for it, and:

In ISO/IEC 9899/1999 (C99) is stated under §3.12:

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

As well under §5:

  1. Environment

An implementation translates C source files and executes C programs in two dataprocessing-system environments, which will be called the translation environment and the execution environment in this International Standard. Their characteristics define and constrain the results of executing conforming C programs constructed according to the syntactic and semantic rules for conforming implementations.

But to which software applications exactly it refers to?

Which set of software in particular?

It is stated as providing a translation AND an execution environment. So it couldn´t be the compiler alone, or am i wrong about this assumption?

About which parts of my system i can think of as part of "the implementation"?

Is it the Composing of the used Compiler with its relying C standard, the operation system, the C standard used itself or a mix between those all?

Does it despite the previous statement also include a piece of hardware (used processor, mainboard, etc)?

I quite do not understand, what an implementation exaclty is.

I feel like i have to be a 100-year experienced cyborg to know what it all includes entirely and exactly.

Community
  • 1
  • 1

3 Answers3

4

Generally speaking, an "implementation" refers to a given compiler and the machine it runs on. The latter is important due to things such an endianness, which dictates the byte ordering of integer and floating point types, among other considerations.

An implementation is required to document its implementation defined behavior. For example you can find GCC's implementation defined behavior here.

Compilers often support multiple versions of the C standard, so each operating mode can also be considered an implementation. For example, you can pass the -std option to GCC to specify c89, c99. or c11 modes.

dbush
  • 205,898
  • 23
  • 218
  • 273
  • It is useful to state that the libraries, operating system, and other supporting things are part of the implementation. GCC can be combined with different headers and library implementations, and these form different C implementations. People focus on the compiler since it is the main face of the C implementation, but GCC interacts with the headers (it sends information to them through special preprocessor macros, and they have responsibilities for supporting various features in response). That is so well knit together that many people do not know about it, but it is important when it breaks! – Eric Postpischil Oct 25 '19 at 16:57
3

I think you have a good formal sense of what it is, and are focusing your question on specifics of real-world implementations, so that's what I'll address. "The implementation" actually tends to encompass a number of components which act and depend upon one another via a number of interface contracts, all of which need to be honored in order to have any hope of the implementation as a whole being conforming.

These include possibly:

  • the compiler
  • possibly an assembler, if the compiler produces asm as an intermediate form
  • the linker
  • library code that's part of the standard library (which is part of the language, as the language is specified, not a separate component, but only for hosted implementations not freestanding ones)
  • library code that's "compiler glue" for implementing language constructs for which the compiler doesn't directly emit code (on GCC, this is libgcc), often used for floating point on machines that lack hardware fpu, division on machines that lack hardware divider, etc.
  • the dynamic linker, if the implementation uses dynamic-linked programs
  • the operating system kernel, if the implementation's library functions don't directly drive the hardware, but depend on syscalls or "software interrupts" or similar defined by the operating system having their specified behavior in order to implement part of the standard library or other (e.g. startup or glue) library code
  • etc.

Arguably you could also say the hardware itself is part of the implementation.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • Add the start-up and termination code that sets up the C environment and calls `main` and handles returns from `main` and program termination. Also, “library code” may include this, but we should be clear it includes the headers as well as the implementations. – Eric Postpischil Oct 25 '19 at 16:52
-1

The C99 Standard defines many things, but some are just not that relevant so they did not care to define them in the Standard in detail. Instead, they write "implementation defined" which means that whoever actually programs a compiler according to their standard can choose how exactly they do that.

For example, gcc is an implementation of that standard (Actually, gcc implements various different Standards, as pmg points out in his comment. But that's not too important right now). If you were to write your own compiler, you can only call it a "C99 Compiler" if it adheres to the standard. But where the standard states that something is implementation dependent, you are free to choose what your compiler should do.

lucidbrot
  • 5,378
  • 3
  • 39
  • 68
  • GCC is not an implementation of the C standard. It is part of an implementation of the C standard. This question does not ask what “implementation defined” means; it asks what an implementation is. GCC plus library routines plus start-up code plus headers plus an operating system plus hardware plus anything else needed to compile, link, and run a C program is a C implementation. – Eric Postpischil Oct 25 '19 at 16:55