Web Search

Tuesday 4 June 2013

C++ Language Part -3

C is a Middle-Level Language

C is often called a middle-level computer language. This does not mean that C is less powerful, harder to use, or less developed than a high-level language such as BASIC or Pascal, nor does it imply that C has the cumbersome nature of assembly language (and its associated troubles). Rather, C is thought of as a middle-level language because it combines the best elements of high-level language because it combines the best elements of high-level languages with the control and flexibility of assembly language. Table 1-1 shows how C fits into the spectrum of computer languages.

As a middle-level language, C allows the manipulation of bits, bytes and addresses – the basic elements with which the computer functions. Despite this fact, C code is also very portable. Portability means that it is easy to adapt software written for one type of computer or operating system to another. For example, if you can easily convert a program written for DOS so that it runs under Windows, that program is portable.

C's Place in the World of Computer Languages


All high-level programming languages support the concept of data types. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common data types are integer, Character and real. Although C has five basic built-in data types, it is not a strongly typed language, as are Pascal and Ada. C permits almost all type conversions. For example, you may freely intermix character and integer types in an expression.

Unlike a high-level language, C performs almost no run-time error checking. For example, no check is performed to ensure that array boundaries are not overrun. These types of checks are responsibility of the programmer.

In the same vein, C does not demand strict type compatibility between a parameter and an argument. As you may know from your other programming experience, a high-level computer language will typically require that the type of an experience, a high-level computer language will typically require that the type of an argument be (more or less) exactly the same type as the parameter that will receive the argument. However, such is not the case for C. Instead, C allows an argument to be of any type so long as it can be reasonably converted into the type of the parameter. Further, C provides all of the automatic conversions to accomplish this.

C is special in that it allows the direct manipulation of bits, bytes, words, and pointers. This makes it well suited for system-level programming, where these operations are common.

Another important aspect of C is that it has only 32 keywords (27 from the Kernighan and Ritchie de facto standard and five added by the ANSI standardization committee), which are the commands that make up the C language. High-level languages typically have several times more keywords. As a comparison, consider that most versions of BASIC have well over 100 keywords.

C++ Language Part -2

The Origins of C

C was invented and first implemented by Dennis Ritchie on a DEC PDP-II that used the UNIX operating system. C is the result of a development process that started with an older language called BCPL. BCPL was developed by Martin Richards and it influenced a language called B, which was invented by Ken Thompson. B led to the development of C in the 1970’s.

For many years, the de facto standard for C was the version supplied with the UNIX operating system. It was first described in The C Programming Language by Brian Kernighan and Dennis Ritchie (Englewood Cliffs, NJ: Prentice-Hall, 1978). With the rise in popularity of personal computers, numerous C implementations were created. In a near miracle, most of these implementations were highly compatible (That is a program written for one of them could usually be successfully compiled using another). However, because no standard existed, there were discrepancies. To remedy this situation, a committee was established in the summer of 1983 to create an ANSI (American National Standards Institute) standard that would define the C language once and for all. The standardization process took six years (much longer than anyone reasonably expected). The ANSI C standard was finally adopted in December of 1989, with the first copies becoming available in early 1990. Today, all mainstream C/C++ compilers comply with the ANSI C standard. Also, the ANSI C standard is a base document of the proposed ANSI C++ standard.

Monday 3 June 2013

C++ Language Part -1

The Foundation of C++


As you probably know, C++ is built upon the foundation of C. When C++ was invented, the C language was used as the starting point. To C were added several new features and extensions designed to support object-oriented programming (OOP). However, the C-like aspects of C++ were never abandoned.

In its current form, C++ is an enhanced version of ANSI standard C. In fact, the ANSI C standard is a base document for the proposed ANSI C++ standard. For this reason, any C++ compiler is by definition also a C compiler. Because C++ is built upon C, you cannot program in C++ unless you know how to program in C. Further, many of the fundamental concepts that form the basis for C also form the foundation for C++.

Since C++ is a superset of C, the material described in this part is fully applicable to C++. The C++ specific features of C++ are detailed in Part 2. The reason that the C like features of C++ are covered in their own section is to make it easier for the experienced C programmer to quickly and easily find information about C++ without having to “wade through” reams of information that he or she already knows. Throughout Part One, any minor differences between C and C++ are noted.