FreeRTOS support for C++ Templates and STL (I.e. Standard Template Library)?

Hi Team,

I have following questions about FreeRTOS support:

  1. Does FreeRTOS support C++ Templates? (for generic programming to create templatized classes methods etc.)
  2. Does FreeRTOS support Standard Template Library (STL). So that we can create queues, lists arrays etc.

Any inputs on this will be very helpful.

Thanks & Regards,

  • Ajit Bhor

You‘re free to use whatever your compiler supports.
FreeRTOS is just an OS which shouldn’t and doesn’t restrict how application code is written. FreeRTOS code itself already takes care about getting seamlessly mixed with C++ application code by exporting its API as extern “C”.
For instance I’m using C++ including STL for my FreeRTOS applications.
The only maybe non-obvious thing you have to take care about is the (thread-safe) heap needed for new/delete operators.
The standard heap implementation (malloc, free, realloc) is usually part of the C standard library (e.g. newlib) which is part of the compiler tool chain. But it requires system support through the _sbrk system call which needs to be implemented. Often there is a syscalls.c file which contains implementations or wrappers for all possible system calls used by the C standard library.
Alternatively one of the provided (optional) FreeRTOS heap implementations can be used for your application code, too.
In this case you have to override the C library heap interface (malloc,free, realloc) with corresponding wrapper functions.
There are some good resources in the net like Dave Nadler’s article worth reading.

FreeRTOS includes the extern “C” statements needed to include its headers from C++ code.
Other than that, it doesn’t do much to provide direct support for C++, nor does it do anything to prevent the use of C++.

I have written a simple set of C++ wrappers for FreeRTOS (https://github.com/richard-damon/FreeRTOScpp) That does some of the things you mention.

One big thing to note, FreeRTOS Queues and Streams do NOT support full classes for their data, but only POD (Plain Ol Data) objects, because they are moved with memcpy, not the C++ copy constructors or assignment operators.