If C / C ++ are native languages then why do they need runtimes?

4

Generally the first thing that came to my mind when I heard the term native language, was a program that ran independent of operating system, communicating directly with the hardware, I always developed in debug mode, when I released a release for the first time I noticed that compilers up to MinGW needed a runtime , if it were an application using Windows API for example would be totally understandable because it depends on libraries operating system. But if there is a need for a runtime then why call native language?

I imagine a hobbyist developing a very simple computer (something like a chip-8) so he starts developing his kernel for the operating system, at some point he's going to have to drop the Assembly and use C / C ++, how will the program handle something so low level without a runtime ?

    
asked by anonymous 31.05.2018 / 02:31

1 answer

6
  

Generally the first thing that came to my mind when I heard the term native language, was a program that ran independent of operating system, communicating directly with the hardware

Wrong, a native language depends on the operating system. At least there is no requirement that you do not need an operating system, and without having one, then becomes fundamental, after all the language alone (the code it generates) can only give instructions for the processor. Direct hardware access is possible, but it is not simple.

  

I always developed in debug mode, when I released a release for the first time I noticed that compilers up to MinGW needed a runtime, if it were an application that used Windows API for example would be totally understandable because it depends on libraries of the Windows operating system.

I think there is a lack of understanding of what a runtime is. It is code needed to perform certain tasks in an easier and safer way.

You do not need a runtime in Assembly, in C either, or almost. To some extent in C ++. Except that in practice it will work, you will have to do everything at hand and you are probably reinventing the wheel in a worse way. You will rarely be getting rid of the code needed to function properly, just doing it in hand.

Do libraries count as runtime or not? In practice without them you can not do anything useful except by rewriting them. What you may be calling runtime are the libraries. It is not wrong to say this, but it is possible to leave it out. You will have little advantage over the Assembly, probably just architecture portability.

The runtime has mechanisms to make your life easier if you use them. Or to solve an implementation or platform problem, not language.

  

But if there is a need for a runtime then why call it native language?

Since this is a wrong premise you should provide a reason why a native language could not have a runtime .

Native language means that the code runs directly on the processor, only that, which does not have an intermediate process of interpretation.

In fact the term is already wrong. There is no native language, there is native implementation. We can say that all language can be native or not. Some are more likely to be one thing or another, but unless something in the specification that requires only one of these directions, neither C nor C ++ has this requirement, you can do a non-native implementation.

  

I imagine a hobbyist developing a very simple computer (something like a chip-8) so he starts to develop his kernell for the operating system, at some point he's going to have to put the assembly aside and use C / C ++

No, it can continue to use Assembly.

  

So how will the program handle something so low level without a runtime?

I do not know how this question makes sense, let alone what the doubt is here. If I understand correctly this question invalidates the original assumptions of the question.

Conclusion

I think you're confusing terms and concepts. There is no relationship between these things.

    
31.05.2018 / 04:46