FreeRTOS with C++

sorinl wrote on Wednesday, March 20, 2019:

Hello all,

When I compile a FreeRTOS project in C++, I get the errors concerning the void pointers issue

  1. a value of type “void” cannot be assigned to an entity of type “TCBt” for
    ** taskSELECTHIGHESTPRORITYTASK()**; (called in tasks.c)

  2. a value of type "void * " cannot be assigned to an entity of type “TCBt” for listGETOWNEROFNEXTENTRY; (called in** tasks.c**, implemmented in** list.h**)

  3. a value of type "void * " cannot be assigned to an entity of type “osmailQcb” in cmsisos.c

I’ve understood that is already available a FreeRTOS version for C++ (with no void pointers) but I couldn’t find it.

Please advise.

Thanks in advance and best regards**

rtel wrote on Wednesday, March 20, 2019:

Which version of FreeRTOS are you using? The latest have removed a lot
of void *, which were only used in the first place due to GCC (or GDB?)
bugs many many years ago that couldn’t cope with type safe opaques.

If you still have an issue with the latest version of FreeRTOS then
please show which lines are causing the issues in particular. Also
please say how you are building the source files - you should be able to
build them as C files and link them into a C++ project (although this is
not a scenario we test ourselves there are several that do).

You can also look in the FreeRTOS Interactive site for some C++ wrappers.

The cmsis file is not outs, so can’t help you there.

richard_damon wrote on Wednesday, March 20, 2019:

One of the big things to remember when using FreeRTOS with C++ is that the FreeRTOS files still must be compiled as C code, not C++ code, as the FreeRTOS code isn’t valid as C++ (largely because it assumes the implicit conversion of pointers to void to other pointer types.

The FreeRTOS headers have the needed code (the conditional extern “C”) to make them interface with C++ code. (but any callback that FreeRTOS calls by name will also need to be declared as extern “C”).

I have a set of wrappers I have shared that when you are using the wrappers, you aren’t using pointers to void, but FreeRTOS itself internally still has some. The recent updates have reduced these a lot as now Task/Queue/Semaphore/etc pointers are pointers to void, but pointers to just forward declared structs so you can’t give a task pointer to a queue by mistake.