C and C++

Pan Pantziarka takes us through the long and distinguished history of C and C++ and associated libraries and development environments.

HardCopy Issue: 39 | Found In: Development | Published: 01/02/2008 | Last Revision: 06/04/2010

“In the beginning there was C.” OK, that’s not strictly true, but compared to relative new-comers such as Java, C#, Ruby and the like, the C language comes from the dark ages of computing. However unlike some of the other languages from that dim and distant age, such as ALGOL, APL and Smalltalk, C remains a language that is still used for new development as well as being used to maintain a hefty part of the IT infrastructure that powers the Internet. And of course C begat C++, which was the most successful of the attempts to add object orientation to C (the other successful attempt being Objective-C). Technically speaking, C is a procedural, block-based, statically-typed, compiled language. It is succinct, with few keywords and constructs, and offers very low level access to the underlying hardware that it runs on. In some senses it’s an assembly language on steroids, complete with direct access to memory locations using pointers and programmer-controlled memory management.

Frameworks and Libraries

There are numerous frameworks and libraries available for C and C++, both open source and commercial (including a number that are dual-licensed). These range from specialist numerical algorithms to graphics engines, charting, communications, XML processing and so forth.

One notable example is Trolltech’s Qt range of cross-platform rich client development tools. Qt is the engine that drives the KDE desktop in the Linux world and which gives developers the chance to create complex, attractive and highly functional GUI programs across a range of platforms (including Windows, Linux and Mac). While Trolltech has released both Java and Python bindings for Qt, the native interface of Qt is C++. In addition to core graphics functionality, Qt also includes powerful XML, database and network functionality.

Other notable frameworks and libraries include the Apache C++ Standard Library, Rogue Wave Software’s SourcePro C++ libraries and the Numerical Algorithm Group’s high-performance, high-precision numerical recipes libraries.

C was initially developed by Dennis Ritchie at Bell Labs in the early 1970s and was used to write the kernel of the Unix operating system. It has remained a systems language ever since although it has also been used to write applications, graphical user interfaces, compilers, utilities and just about everything else. In addition to the small number of keywords, C depends on the availability of standard libraries to extend the language and to provide higher level abstractions. The syntax employed by the language is straightforward and has strongly influenced many of the programming languages that have followed it. The use of braces for code blocks and the semi-colon for the statement delimiter is familiar to shell scripting, Java, JavaScript, C# and many other languages. It has been a key influence on the development of programming languages as a whole and continues to be so to this day.

C Programming Language Book
Possibly the best description of any language and available at www.greymatter.com/36427.

While C remains strong as a systems language, particularly at the operating system and device driver level, it also retains a strong position in the world of embedded systems. The availability of cross-compilers and other development tools for the embedded system market make it an extremely powerful language for embedded devices. Real-time software is a related area in which C excels, primarily because it can talk to the hardware and because C compiles down to very efficient (and hence very fast) machine code. The connection to Bell Labs was also important for the development of C++ by Bjarne Stroustrup. It was while working at Bell Labs that Stroustrup began working on an extension to C that added higher-level object-oriented features including classes, inheritance and operator over-loading. These higher-level features do not preclude the original features of C so pointer arithmetic, low-level memory management and direct access to hardware ports are all still possible using C++. This combination of low and high-levels of abstraction makes C++ a language that is still ideally suited to operating system kernels, graphical user interfaces, device drivers and such like. Unlike some of the other object-oriented languages, particularly C# and Java, C++ implements multiple rather than single inheritance which means that a class may inherit from a number of parent classes. This adds a level of complexity that has helped give the language a reputation for being difficult to master. Additionally C++ code is normally compiled directly to machine code, unlike Java or C# which compile to byte code that is executed in a virtual machine.

Development Environments

Given the origins of C and C++, it should be no surprise that support for the languages is particularly strong in the open source world. The gcc (GNU compiler collection) is the main open source C/C++ compiler available across multiple platforms and forms a key part of most Linux and BSD operating system distributions. While gcc is a command line tool, there are numerous front ends available as well as a slew of supporting tools (make, lint and the whole panoply of essential development utilities).

Support is also included in the two heavy-weight open source IDEs, namely Eclipse and NetBeans. The NetBeans C/C++ Pack enables developers to link to a choice of compilers and debuggers, and enables users to develop C and C++ applications on Windows, Linux, Solaris and Mac OS X. The Eclipse CDT (C/C++ Developer Tooling) provides similar functionality.

In terms of commercial offerings the big three are Microsoft’s Visual Studio 2008, CodeGear’s C++ Builder and Intel’s C++ Compiler 10.1. Note that while the Microsoft and CodeGear products are complete development environments, Intel’s is a compiler that is heavily optimised for Intel CPUs and still requires a separate IDE for writing and debugging code. Given the long history of C++ investment from both CodeGear (who as Borland produced the legendary Turbo C and Turbo C++ products) and Microsoft it is easy to see why these products remain market leaders.

Tools for C/C++ development on embedded systems and cross-compilers are available from Crossware for the ARM, 8051, ColdFire, M68xxx and other chip families. Hi-Tech Systems provide a range of compilers and tools for a similar range of chip families as well as the Holtek, ArcLite, dsPIC/PIC24 and other embedded controllers and platforms.

Like C, C++ also depends on a standard library to extend and enhance what is still a very stripped down language. In the case of C++ an important part of this is the Standard Template Library (STL) which supplies a set of high-level data structures including arrays, maps and iterators. Where do C and C++ fit in with the two big enterprise IT platforms of Java and .NET? The first and most obvious point is that the operating systems on which these platforms sit are most likely written in C and/or C++. Secondly, the .NET CLR and Java JVM are also written in C++, as are the compilers for C# and Java respectively – indeed both Microsoft and Sun Microsystems have considerable experience and investment in C++ and continue to support the language. Finally, both these platforms also support code written in C and C++. In the case of Java the code that accesses the operating system directly using the Java Native Interface (JNI) is written in C and C++. For the .NET framework there is C++/CLI which is Microsoft’s set of extensions to ‘standard’ C++ that fit in with the needs of the Framework and provide access to garbage collection and other services which have traditionally not been included as a standard part of the language. It should be clear by now that C and C++ are by no means legacy languages supported on obsolete platforms. While they may not have the kudos of newer and trendier languages, you can bet your life that those newer languages were probably coded in C and/or C++ to begin with.

CodeGear C   Builder 2007 debugging tools
Find out exactly what's happening when your code runs with the CodeGear C Builder 2007 debugging tools.

How to shoot yourself in the foot in C++:

/* You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing medical assistance is impossible since you can’t tell which are bitwise copies and which are pointing at others saying, “That’s me, over there.” */

Share and Bookmark  

Comments

Be the first to comment about this article...

Leave a comment

You must login to place comments.