0

I'm working on a kernel for a proprietary embeded system. I've had no issues but I'd like to expand its capabilities directly. I made it run C. I did so pretty much by giving my kernel a stack.

My question is C only required a stack to be able to execute cross-compiled code. What beyond a stack would I need to provide at the kernel level for the execution of cross-compiled C++ code. That is, does it need a heap, more complex data types and structures, et al?

To me it's become a chicken or egg problem as anything that I think C++ might need is easily written in C++.

NB: I have endeavored to research this question here and elsewhere and have not found an answer to this specific issue. I have tried to make this a very specific question in accordance with the rules here, please help me if revisions are necessary.

  • 2
    you'll need the runtime library. If that's linked statically it won't need anything more than C. – ratchet freak Mar 10 '16 at 14:22
  • 2
    Details are compiler and ABI specific. – Basile Starynkevitch Mar 10 '16 at 14:25
  • 1
    "To me it's become a chicken or egg problem as anything that I think C++ might need is easily written in C++." Have you noticed that many components of the C++ standard library (especially the STL) and third-party libraries such as Boost are "header-only" classes? There is a strong correlation between your observation and the C++ libraries in that regard... – user22815 Mar 10 '16 at 19:01
  • Since there are kernels written in C++, it seems self-evident that C++ does not need any kernel support at all, no? – Jörg W Mittag Mar 11 '16 at 0:53
  • No Jorg, with all politeness, there are some kernels that are capable and some that aren't, implying elements unknown are needed. My question was on the specifics. – Mikeologist Mar 11 '16 at 17:37
4

You don't strictly need a heap to run either C or C++ programs that are compiled for your platform, but if you want to use heap-allocated objects or memory blocks, then you will need a heap.

C++ uses heaps more than C code (ie routinely under the covers in libraries). In particular most use of the STL will want a heap, and C++ code uses the STL a fair amount. You can require a different allocator for STL containers, but I think forcing them to use the stack might be a step too far for most people, if its even possible at all.

Other than that, I guess it depends what code the compiler emits.

  • A note I should have mentioned is that I am quasi-emulating arm assembly by matching my machine instructions to the arm assembly instruction set names. So ultimately to allow for the native use of C++ I will need to get C++ standard library, runtime library, stl and a heap all working? Won't be easy, but I think I can handle that. – Mikeologist Mar 10 '16 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.