Rivers Shall
Rivers Shall

Reputation: 561

What does the "implementation" mean in "implementation (in)dependent"?

What does the "implementation" mean in "implementation (in)dependent"? And what is the difference between "implementation (in)dependent" and "machine (in)dependent"?

I use C so you may explain it in C.

Upvotes: 0

Views: 2005

Answers (2)

Eric Postpischil
Eric Postpischil

Reputation: 222942

When the C standard discusses an implementation, it means an implementation of the C language. So an implementation of C is everything1 that is needed to interpret and execute C programs.

Typically, that includes a compiler, the accompanying or compatible developer tools such as a linker and a software library providing support routines, an operating system and its components such as the loader, and a computer system to run it on.

On one computer system, you can have multiple compilers installed. You can have GCC and Clang. When programs are compiled with GCC and executed, that is one C implementation, and, when they are compiled with Clang and executed, that is a different C implementation, even though they both run on the same system. One C implementation is the particular complete set of stuff that is used translate and execute C programs.

Since the C standard does not completely specify how everything you write in a C program behaves, some things can be different between implementations. Notably, how many bits are in an int can vary. These things are implementation-dependent.

Uses of “machine dependent” when referring to C are often imprecise use of language when “implementation dependent” is really meant. There is a strong connection between the features of a machine and the features of a C implementation. When somebody writes a compiler for a machine that has only 32-bit registers and 32-bit integer arithmetic instructions, they are most likely going to design their compiler so that int is 32 bits. However, this is a choice. It is completely possible to write a compiler for a 32-bit machine in which int is 64 bits or 16 bits. The former may be more difficult (because they have to construct 64-bit arithmetic by compiling single C arithmetic operators to multiple instructions) or wasteful (because doing only 16-bit operations on a machine capable of 32-bit operations does not use its full power), but it is completely possible. So the actual properties of a C implementation are a function of the whole implementation, not solely of the machine it runs on.

Footnote

1 The C standard defines an “implementation” to be a “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” (C 2011 [N1570] 3.12). However, one of course also needs hardware, or at least a specification of hardware, in order to execute or understand the executable program that results from a compiler. So we may consider an implementation to be everything that is required to interpret and execute a C program.

Upvotes: 3

John Zwinck
John Zwinck

Reputation: 249293

In C (or C++), the "implementation" refers to the software "around" the compiled program, such as the compiler, standard libraries, and so on. For example, GCC provides a C "implementation" for x86-64, as well as one for 32-bit x86, and several others. Microsoft provides an "implementation" for x86-64, 32-bit x86, and previously some others. An example of something "implementation dependant" is the source code character set and encoding (e.g. Unicode support in the program source). Another example is how files are found when you #include them.

The "machine" refers to the hardware and probably part of the kernel. For example you might have a machine with 64-bit pointers, or one with 32-bit pointers. You might also have a machine where integer arithmetic is not two's complement. Those things are machine dependant.

Upvotes: 2

Related Questions