C++@embedded

Selected C++ Features


We don't enable Embedded C++ (EC++) since it disables most features of C++. Instead, we only disable some C++ features which will cause performance penalty, especially the "Exceptions" and "RTTI" features which are already disabled by default.

C++ Language FeaturePerformance PenaltyEC++ SubsetOur Choice
ClassesNoYesYes
OverloadingNoYesYes
Operator OverloadingNoYesYes
Inheritance (derived classes)NoYesYes
Wide Character SupportNoYesUTF-8
Multiple InheritanceNoNoYes
TemplatesNoNoYes
NamespacesNoNoYes
Polymorphism (virtual functions)Only when usedYesYes
Virtual Base ClassesOnly when usedNoYes
Dynamic CastsOnly when usedNoYes
Run-time Type Identification (RTTI)Yes, even not usedNoNo
ExceptionsSevere, even not usedNoNo

TI C++ compilers supply a full implementation of the C++ library, including the STL. The C++ additions to the library are obtained from Dinkumware, a world class supplier of C++ libraries.

Task Encapsulation


It will be more convenient if RTOS can provide encapsulated C++ classes for task run-loop. PicOS has built-in a Task class to simplify the usage.
class MyTask: public pos::Task
{
private:
    int x;
public:
    MyTask();
    ~ MyTask();
    run();
};
where pos is the namespace of PicOS. run() is the run-loop which is declared as a virtual function to be further defined by the derived class.
void MyTask::run()
{
    while(1){
        msg_t msg;
        if(msgPend(&msg, 1000)){
            switch(msg.MsgID){
                case MSG_KEY_DOWN:
                    ...
                    break;
                case ...
            }
        }
    }
}