Is there any reason to use C instead of C++ for embedded development?

后端 未结 30 3725
既然无缘
既然无缘 2020-11-30 17:20

Question

I have two compilers on my hardware C++ and C89

I\'m thinking about using C++ with classes but without polymorphism (to avoid vtables). The main r

30条回答
  •  孤街浪徒
    2020-11-30 18:10

    I recommend using the C++ compiler, but limiting your use of C++ specific features. You can program like C in C++ (the C runtime is included when doing C++, though in most embedded applications you don't make use of the standard library anyway).

    You can go ahead and use C++ classes etc., just

    • Limit your use of virtual functions (as you've said)
    • Limit your use of templates
    • For an embedded platform, you'll want to override the operator new and/or use placement new for memory allocation.

提交回复
热议问题