This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why can't you add a new class in Segger ?

What hidden settings am I missing this time in the awful Segger studio ?

I get an error :

unknown type name class

When I compile with this new class called Test.cpp :

.cpp file:

#include "Test.h"


Test::Test()
{
    
} 

and the .h file :

#include <stdlib.h>
#include <stdio.h>

    class Test
    {
        
        
    public:
        
        Test();
     
    
        
    private:
        
         
    
    };

EDIT:

Not sure why people are down voting but I think it's a real problem, at least for a beginner .

if I change the main to main.cpp I get 250 errors, some of them are :

'->' cannot appear in a constant-expression
'&' cannot appear in a constant-expression
a cast to a type other than an integral or enumeration type cannot appear in a constant-expression

They are coming from C files used by Nordic (drivers and libraries). The project was an example project from SDK, and I'v added other things to it.

I asked some people about it on the net, and they said I can't just mixed C and C++ files, so for example:

//main.cpp
#include "flash.h"
int main(void){}

Will produce errors because I include C file in C++ file , where the C might not be properly writen for C++.

Some of the errors comes from lines like this :

NRF_GPIOTE_TASKS_OUT_0     = offsetof(NRF_GPIOTE_Type, TASKS_OUT[0]), /**< Out task 0.*/
Parents
  • The question whether to use C or C++ is subjective, opinionated. You can mix C and C++, but it takes some learning and work. The main thing you need to understand is C++ "name mangling" (the two different calling conventions) and when to wrap C code that is being compiled by the C++ compiler in "extern "C" {}" wrapper. Nordic doesn't "officially" support C++ but much of their code is C++ compatible. I use the C++ compiler with the Nordic SDK, but I don't use all of the SDK, and in a few places I made a few minor hacks to the SDK, and I need to ignore a few warnings from the C++ compiler. So maybe I get C++'s advantage of OOP, but it comes with the cost of dealing with mixed C/C++.

Reply
  • The question whether to use C or C++ is subjective, opinionated. You can mix C and C++, but it takes some learning and work. The main thing you need to understand is C++ "name mangling" (the two different calling conventions) and when to wrap C code that is being compiled by the C++ compiler in "extern "C" {}" wrapper. Nordic doesn't "officially" support C++ but much of their code is C++ compatible. I use the C++ compiler with the Nordic SDK, but I don't use all of the SDK, and in a few places I made a few minor hacks to the SDK, and I need to ignore a few warnings from the C++ compiler. So maybe I get C++'s advantage of OOP, but it comes with the cost of dealing with mixed C/C++.

Children
No Data
Related