Is a standard of ISO language. It was developed in 1979 by Bjarne Stroustrup at AT & T as an extension of the C programming language. C provides both efficient and low-level programming and programming at a high level of abstraction.
- 2.1 Language Design 2.1.1 Memory Management
- 2.1.2 Incomplete object-orientation
- 2.1.3 Complicated grammar
- 2.1.4 Undefined behavior
- 3.1 C compiler
- 3.2 C Programming
- 4.1 Objective- C
- 4.2 Java and C #
- 5.1 genesis
- 5.2 Further development of the C programming after 2005 5.2.1 Improvements to the core language
- 5.2.2 Extension of the program library
Areas of application
C is used both in system programming and in application programming and heard in both areas of the most common programming languages.
Typical fields of application in system programming are operating systems, embedded systems, virtual machines, drivers, and signal processors. C takes the place here often one that was formerly only assembly language and C language reserved.
In the application programming C is primarily used in applications where high demands are made on the efficiency to exploit specified performance limits as well as possible technical conditions. In the years 2000 to about 2010 C from the domain of the application programming has been pushed back to the part of the languages Java and C #. Since gaining C with the advent of mobile devices due to resource-saving and efficient, thereby saving power of those applications back market share in the application programming back.
The C language consists of very few key words ( " core language "); their actual functionality it gets - as well as the C language - by the C standard library as well, depending on the application, additional libraries and frameworks. C puts an emphasis on the language tools for the development of libraries. This makes it favors generalized mechanisms for typical problems, and has barely into the language of individual solutions.
One of the strengths of C is the combinability of efficient, machine-oriented programming language with powerful means easy to summarize complex implementation details and largely hidden behind abstract command sequences. In particular, the template metaprogramming comes into play, a technique that allows an almost uncompromising combination of efficiency and abstraction.
Some design decisions are, however, also often criticized:
C waived garbage collection, so that other memory management techniques, mostly RAII, must be used. Moreover, it is possible to manage memory manually, although thereof is usually strongly discouraged.
In C include private properties (variables and methods) usually with the published in the header file interface. This creates at compile time and run time dependencies of the objects to the code points that they use.
These dependencies can by certain constructions, such as the pimpl idiom (pointer to implementation idiom ) can be avoided. The private fields of the class ( example_class ) in a private, forward - declared class to be moved (eg example_class :: impl ) and a pointer to an object of this subclass ( example_class :: impl * impl_ptr ) remains in the actual class. The definition of the implementing class will take place in the implementation of a public class and so is the source code that uses only the header file invisible. The fact that the sub-class is only referenced by a pointer, all code changes are transparent to private fields and binary compatibility is maintained.
In addition, the memory areas of the individual objects are not only at run time ago ( deliberate or accidental ) mutual changes.
The grammar of C is often classified as difficult. For example, the meaning of the following code snippet is completely dependent on the context:
Either could be " A" class template be, which would mean that the code creates a new local variable named "D" that has the "B" and "C" instantiated template as a type. Alternative " A", " B" could, "C" and "D" to be variables, which would mean that the code would first apply the less - than operator to "A" and "B ", the return value would reject would, and apply the greater - than operator to "C" and "D " following, which returns the return value of the entire expression would.
The behavior of the various language constructs is not defined. This means that the standard does not purport what happens in such a case. The effects range from implementation dependent (ie, depending on the target machine and compiler, the construct may behave differently ) about nonsensical results or program crashes to dangerous vulnerabilities. While in part this way enables big optimizations for the compiler, it comes out the other side repeatedly to the fact that incorrect source code is implemented by the new compiler versions to unexpected and seemingly absurd way. So too late verifications carried out be optimized away or loops that access an invalid index of an array, replaced by empty infinite loops.
Important for the understanding of undefined behavior is in particular that never only a single operation is invalid, but the entire program is invalid and not well-formed C is more.
- Overflow of signed integers (even, for example, when converting from unsigned int to int )
- Null pointer dereferences
- Array accesses with invalid index
- Shift operations with right operand out of range
Compatibility with C
To tie in with the spread of the C programming language was C as an extension of C according to the former level in 1990 (ISO / IEC 9899:1990, also called short- C90 ) were designed.
Compatibility with C C forces for the continuation of some thereby acquired disadvantages. This includes the sometimes difficult -to-understand C syntax, the preprocessor regarded as obsolete and various dependent of the platform details of the language that complicate the porting of C programs between different types of computers, operating systems and compilers.
Some C - language constructs in C have a slightly different meaning or syntax, so some C programs need to be adapted to can be translated as a C program. Further changes at C found in 1999 (ISO / IEC 9899:1999, aka C99 ) and 2011 (ISO / IEC 9899:2011, aka C11) ie after the first standardization of C instead, so that there has flowed changes not in C 98 could be considered. In the C revision of 2011, a part of the new features of C99 is given; on the other hand, new features have been added to the standard C, which are not compatible with C 11.
Language features in detail
C is based on the C programming language as defined in ISO / IEC 9899:1990 described. In addition to the existing C options provided by C other data types as well as novel type conversion options, classes with multiple inheritance and virtual functions, exception handling, templates ( stencils ), namespaces, inline functions, operator overloading and function names, references, operators are free memory management and with the C standard library an expanded library.
The following code is a simple C program based on the standard output device (usually screen ) outputs the text " Hello world! "
When main is the main function. It is available in any C program and serves as the entry point of the program. The program is executed by the main function is called, which in turn can call other functions. The standard allows two versions of the main ( ): The first has no function parameters (as above) and returns an int, the second version takes an integral scalar and a doubly - indirect pointer (an array of strings), so as to to access command-line parameter (which is in some programs not needed and therefore not mandatory):
Cout is an object of the ostream class, which is in the namespace " std" and is addressed by the scope resolution operator (:: ). cout is declared in the iostream header file and redirects the output to the output stream stdout.
Std :: endl outputs a newline and flushes the buffer so that the data in it is immediately output (and thus visible on the screen ) are.
The << operator calls the output operation; he is in the std :: ostream class overloaded and is inherited from std :: ofstream.
The implementation of a C compiler is considered expensive. After the completion of the linguistic norm in 1998, it took several years until the language of C compilers was largely supported.
Among the most common C compilers include:
- The compiler is included with Microsoft Visual C is one of the most widely used for the operating system Windows.
- The g is the C expression of the GNU Compiler Collection (GCC ); g is open source and freely available. The g supports a variety of operating systems ( including Unix, Linux, Mac OS X, Windows and AmigaOS ) and processor platforms. GNU C exists since 1987 and is thus one of the oldest C compiler.
- Comeau of C . The so-called " front-end " of the compiler, so the part that implements the analysis phase, was created by the company Edison Design Group (EDG ), which specializes in the development of compiler front-ends and their C - front -end is integrated into many other commercial C compilers. The Comeau compiler can also be tested via the Internet.
- The Intel C compiler also uses the mentioned C front-end of EDG. The Intel C compiler generates machine code for Intel processors on the operating systems Windows, Linux and MacOS X. Since the programs compiled with the Intel C compiler to exploit the instruction set of the Intel processors especially well, they produce highly efficient programs for these platforms. ( Compilations of the Intel compiler also run on AMD chips usually faster than compilations of alternative compiler optimization flags corresponding locks Intel, however, -. The lock can be canceled )
- Clang, a frontend for the Apple -sponsored cross-platform compiler infrastructure LLVM, which is used among other things in the integrated development environment Xcode.
The wide range of services and the diverse design possibilities of language and the libraries would result in relatively long training periods. Compared with C C provides an enormous wealth of language resources.
Comparison with other languages
C was not the only approach, the programming language C to expand features that simplify object-oriented programming. In the 1980s, the programming language Objective- C, but in contrast to C was based on Smalltalk and Simula was not. The syntax of Objective- C differs greatly among other things because the Smalltalk roots of C . The most important application of Objective- C is the programming operating systems Apple iOS and Mac OS X as well as under the OpenStep API.
Java and C #
The programming languages Java and C # have a similar, likewise declined to C syntax as C , are also object-oriented and support for some time type parameters. Despite superficial similarities, they differ conceptually from C in part considerably.
Generic techniques complement the object-oriented programming to type parameters and thus increase the recyclability once coded algorithms. However, the generic Java extensions are applicable only on classes, not on primitive types and data constants. In contrast, relate the generic language extensions of C #, the primitive types with a. This is however an extension for generics at runtime, although tailored to complement the compilation time C templates useful, can not replace but.
Just the generic programming makes C a powerful programming tool. While object-oriented programming in Java and C # still the central abstraction mechanism is, this type of programming in C is declining. So deep class hierarchies can be avoided, and in favor of efficiency and minimize resource consumption is dispensed with in many cases, polymorphism, one of the fundamental components of the object-oriented programming.
Emergence and development
The idea for a new programming language Stroustrup came through experience with the programming language Simula during his PhD at Cambridge University. Although Simula appeared suitable for use in large software projects, the structure of language but difficult to create highly efficient programs. In contrast, efficient programs could indeed write the language BCPL, for large projects BCPL was in turn but unsuitable.
With the experience from his doctoral thesis advanced Stroustrup at AT & T Bell Laboratories as part of investigations of the Unix operating system kernel with respect to distributed computing from 1979, the programming language C. The choice fell on the C programming language, because C was a multi-purpose language, which produced fast code and was easy to port to other platforms. As the Unix operating system supplied C language also had a considerable spread.
One of the first extensions was a class concept with data encapsulation, for which the language Simula -67 was the primary model. After that derived classes were added, a stricter type system, inline functions and default arguments.
While Stroustrup "C with Classes " developed ("C with Classes" ) ( which later C ), he also wrote cfront, a compiler that initially generated C code as an intermediate result from C with Classes. The first commercial version of cfront was released in October 1985.
1983 C with Classes was renamed to C . Extensions were therein overloading of function names and operators, virtual functions, references, constants, a modifiable heap management and improved type checking. The possibility of comments, which are attached to the end of the line was taken over from BCPL ( / /).
In 1985 the first version of C , which represented an important reference version, since the language was not yet standardized. 1989 appeared the version 2.0 of C . New in it were multiple inheritance, abstract classes, static member functions, const member functions and the expansion of access to protected model. In 1990 the book The Annotated C Reference Manual, which served as the basis for the subsequent standardization process.
Relatively late in the language templates, exception handling, namespaces, new casts, and Boolean types have been added.
In the course of further development of the C language also extended over C standard library created. First Supplement was the Stream-I/O-Bibliothek, the replacement for traditional C functions such as printf () and scanf () provides. One of the major extensions of the standard library, later joined by the integration of large parts of the developed at Hewlett -Packard Standard Template Library (STL ).
After years of work, finally in 1998 the final version of the language C ( ISO / IEC 14882:1998 ) has been standardized. 2003 ISO / IEC 14882:2003 was approved, an improvement of the standard of 1998.
The current version of C ( July 2012) is an ISO / IEC 14882:2011, also known as C 11.
C 11 introduces lambdas ( anonymous functions), and facilitated treatment with type inference via the auto keyword (which now no longer a storage class specifier is ) on the one hand and the keyword decltype other.
A for statement makes working with STL containers and arrays, and it may directly consecutive angle brackets are used in templates: map < int, vector
Threads of the C language concerning computing time and memory, were treated in the so-called technical report ISO / IEC TR 18015:2006.
Further development of the C programming after 2005
To keep up with the latest developments in the rapidly -changing computer technology step, but also for the repair of known weaknesses, the C standardization committee worked out the next major revision of C with C 0 x has been unofficially abbreviated, in which the sequence of digits a rough should imply assessment of the possible release date.
The primary goals for the evolution of C were improvements in system programming and the preparation of program libraries. Moreover, the learnability of language for beginners should be improved.
In November 2006, the target date for completion in the year 2009 has been set. In July 2009, this date was changed to 2010 at the earliest. In August 2011, the revision was unanimously adopted by the ISO authority and officially published on 11 October 2011 as the ISO / IEC 14882:2011. Unofficially called the version of C 11.
Improvements to the core language
C 98 revealed some typical problem areas of programming from not enough, for example, the support of concurrency (threads), their integration into C , in particular for use in multi-processor environments, a revision of the language made inevitable. The introduction of a memory model guarantees the language for concurrent operation have been defined to both resolve ambiguities in the processing sequence as well as in certain cases, maintain, thereby creating room for optimizations.
At the broader language extensions also included the automatic type inference to derive result types of expressions, and the so-called R- value references that help can then also be realized as a complement to the already existing copy objects shifting, as well as range-based for loops ( foreach ) over container and built-in fields.
Expansion of the program library
In April 2006, which gave the C standardization committee called first technical report ( TR1 ) found a non-normative complement to the currently valid, as defined in 1998 library, will be studied with the extension proposals before a possible inclusion in the C standard library to their practical usefulness. Many compiler vendors provided the TR1 with their products.
Included were, inter alia, regular expressions, various smart pointers, unordered associative containers, a random number library, tools for C metaprogramming, tuples and numerical and mathematical libraries in TR1. Most of these enhancements came from the Boost library from which they were taken over with minimal changes. In addition, all library extensions to the 1999 revised C programming language ( C99 ) were contained in a form adapted to C form.
With the exception of numerical and mathematical libraries all TR1 extensions have been added to the language standard C 11.
Also own library to support threads was introduced.
The name " C "
The name C is a word created by Rick Mascitti, an employee Stroustrup, and was used for the first time in December 1983. The name comes from the combination of the previous C language and the increment operator " " increments the value of a variable ( increased by one ). The inventor of C , Bjarne Stroustrup, C , first called "C with Classes" (C with classes ).
Often criticism of the language includes for example:
- C is very complex and error-prone to program. We need a long time to make it a good command and many features are considered to be extremely complex.
- C was built on low-level standard; while there are many features of higher abstraction languages have (classes, generic classes / functions etc.) are perceived as important things not present ( Garbage Collection).
- Although C is considered to be fast, for example, because of the opportunity to work freely with pointers, but this power was needed on today's fast computer systems, only in exceptional cases: While it makes sense, operating systems, or the like. to write in C , it is using software much cheaper to write application programs in high-level languages , since they are easier to maintain and still had sufficient power.
- Typically, in conjunction with C is the quote from Bjarne Stroustrup:
" In C it 's harder to shoot yourself in the foot, but when you do, you blow off your whole leg "
" In C it's harder to shoot yourself in the foot, but if you do, then is equal to the whole leg off. "