Global Sources
EE Times-Asia
Stay in touch with EE Times Asia
EE Times-Asia > Embedded

Exploring various embedded programming languages

Posted: 25 Sep 2014 ?? ?Print Version ?Bookmark and Share

Keywords:C? embedded applications? object oriented programming? Java? JavaScript?

Notwithstanding its challenges, C syntax has been the basis for a number of other languages (as we shall see). Apart from needing care with layout, C has a number of other "flexibilities" that can lead to problems.

???Pointers are powerful but can easily lead to confusion.
???The language is weakly typed, thereby facilitating accidental conversions, which can very easily lead to subtle errors.
???Dynamic memory facilities are quite primitive and not well suited to real-time systems.
Many C users value the language's strengths and have taken action to mitigate its weaknesses. This has resulted in a number of approaches to constrain the use of C to avoid the pitfalls. Probably the best-known example is MISRA C, which started out in the automotive world but is finding favour elsewhere.

Though object oriented programming (OOP) was not a new idea (at least one such language existed in the mid-1960s), it really became fashionable in the 1980s. As a result, a number of languages appeared, several of them based on C. This is probably a good time to look at the "family tree" of programming languages, shown below.

The language family tree.

A number of C-derived OOP languages have survived, but the one that really took hold and is popular for embedded development is C++, which was designed by Bjarne Stroustrup at Bell Labs.

One of the key factors in the success of C++ was its initial implementation. Instead of writing a conventional compiler, Stoustrup wrote a pre-processor"cfront"that translated C++ into standard C. This meant that the new language was ready for use just about anywhere a C compiler was available. Nowadays, special C++ compilers are very common, but the pre-processor approach gave the language a strong kickstart.

The point of OOP is to aid the development of larger software projects. This is a challenge increasingly experienced by embedded developers. Using an OOP approach can enable each programmer to focus on his or her own area of expertise without necessarily understanding every aspect of the whole application.

C++ can be used in two ways: It can simply be regarded as "a better C language" on the basis of a number of facilities and constructs that benefit programmers, or it can be used as a true object oriented language. The latter approach can be very useful for embedded applications, since it enables the encapsulation of specialist code, such as device access.

A key feature of C++ is the notion of a class. A class in C++ is somewhat like a structure in C, with some specific differences:

???A class can contain code as well as data.
???Code and data can be hidden from users of the class.
???Special functions may be included in a class to enable operators to define that function with instances of the class.
???A class is essentially a new data type; instances of the class are called "objects."
???The syntax of object definition is simpler than structure instances; just the class name needs to be quoted.
A simple example of a C++ class definition is as follows.

Here is some code that uses the class.

?First Page?Previous Page 1???2???3???4?Next Page?Last Page

Article Comments - Exploring various embedded programmi...
*? You can enter [0] more charecters.
*Verify code:


Visit Asia Webinars to learn about the latest in technology and get practical design tips.

Back to Top