Object Oriented Programming in C

Embedded software development is slowly moving towards object oriented analysis, design and programming. The introduction of object oriented technologies in some systems has not happened due to lack of C++ support on some platforms.

This article focuses on platforms where C++ compilers are not available. The developers working on these platforms should still be able to use object oriented analysis and design. When it comes to final code development they can use C.

The following sections cover an example of C++ code and its implementation in C.

  • C++ Source Code: C++ source files implementing TerminalManager and Terminal classes.
  • C Source Code: TerminalManager and Terminal implemented in C for a platform that does not support C++.

C++ Source Code

Terminal Manager and Terminal C++ header and source files are shown below:

Terminal Manager

TerminalManager.hpp

TerminalManager.cpp

Terminal

Terminal.hpp

Terminal.cpp

Msg.hpp

C Source Code

Terminal Manager and Terminal C header and source files are shown below. The important points to note are:

  • Data members of a class map to C structures
  • Methods of a class map to C functions with the "data member" structure pointer as the first parameter.

TerminalManager

TerminalManager.h

TerminalManager.c

Terminal

Terminal.h

Terminal.c

Msg.h

Explore More