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

Could i use c++ instead of c?

Hi,

i have a generell question. First i have to say i am not the best programmer, but maybe some one with more experience then me could help me.

Does it make sense to use the C examples and port them in to C++ classes and use C++ instead of C?

What would be the disadvantage of using C++ ? Is some one using C++? I thought i could use eclipse + gcc so i could use c++.

Best regards,

Nils

  • Hi Nils,

    I'm using C++ for decades now and I can't see why C++ wouldn't make sense to embedded software development. Not just for the OO support build into the language but especially for the new features coming with C++11 (Here a link to a talk from Rainer Grimm on the last years meetingcpp). SW development is about communicating a solution to a problem. And this solution must be readable not only to the compiler but to our selfs reading the software years later and to our colleagues. I think C++ provides better means to address this compared to C. And C++ can be easily be used with C if you want to use SW written in C.

    You must be aware, that there are some features like exceptions and runtime type informations that you most likely don't need but increase the code size a lot. But this features can be disabled in most compilers.

    Eclipse + CDT is for sure a good IDE but especially for embedded projects, I would go for a command line build using very common standard tools (make/cmake + gcc for example) and then adding an IDE on top of this. This gives you the guaranty, that you can build (and thus change) the software even in 10 years without the need to keep an old computer with the old OS where the old IDE is running on.

    best regards,

    Torsten

  • I'm using C++ for my project with Eclipse+gcc. All you need to do to use C++ to write your app is to declare SDK includes and interrupt handlers as extern "C" {...}.

    And you need to add this file to your project: sys.c

  • Hi,

    thank you for your answers it is nice to hear that it should work to use C++ :)

    @ Nikita was this the only thing you had to do? Where did you get this file from?

    @ Torsten I think the same about readability for code as you. I am really not the best programmer, i learned C++ in study and then i had to do some C works for micro controllers but i really liked to see the OO coherence of stuff like i have it an real world and like i have it in a uC.

    I will talk to an programmer and think i will try it with eclipse + CDT first to see how it works to me. And i think it will be interesting to learn the new C++ features thanks for the info sheets i think it is time for a new book there are really big changes ^^.

    Best regards Nils

  • Yes, that's all you need to do.

    sys.c is to avoid linkage of exception handling and other BIG stuff like malloc and RTTI when using pure virtual functions. I get it from here: electronix.ru/.../index.php

Related