Why are Linux, MacOS and other operating systems written in C and not in C++? Isn't C++ C with new features?
为什么Linux,MacOS和其他操作系统用C编写而不是用C ++编写? C ++ C不具备新功能吗?
8 个解决方案
#1
18
The very short answer is that no entirely new operating systems of any significance have been created at all since C++ attained maturity in the late 90's. And using C++ is not, by itself, nearly a compelling enough reason to completely re-write an existing successful OS.
非常简短的答案是,自从C ++在90年代后期成熟以来,根本没有创建任何重要的新操作系统。并且使用C ++本身并不是完全重写现有成功操作系统的充分理由。
#2
18
C++ is used widely for operating systems. Big parts of Windows is written in it.
C ++广泛用于操作系统。 Windows的大部分内容都写在其中。
But the OS isn't one monolithic blob. There are different layers and components to it. A few bits and pieces pretty much have to be written in assembly, because there is no portable way to implement them: this is low-level handling of the CPU and other hardware, which is abstracted away in higher level programming languages.
但操作系统不是一个整体的blob。它有不同的层和组件。因为没有可移植的方法来实现它们,所以必须在汇编中编写一些零碎的部分:这是对CPU和其他硬件的低级处理,这是在更高级别的编程语言中抽象出来的。
Then there is a layer which can be written in a higher level language, but it just can't rely on other code. It provides a few basic services that are needed for the next layer, and so it has to just work on its own.
然后有一个层可以用更高级别的语言编写,但它不能依赖其他代码。它提供了下一层所需的一些基本服务,因此它必须独立工作。
C++ can be used there, but there are some limitations. C++ requires the runtime library to implement quite a bit of functionality (exception handling, for example), which might not be available (or which it might not be desirable to make available at that level), and so C may be a better solution there. (Although an alternative option is to use C++, but simply avoid features that rely on this missing functionality)
可以在那里使用C ++,但是有一些限制。 C ++要求运行时库实现相当多的功能(例如,异常处理),这些功能可能不可用(或者可能不希望在该级别提供),因此C可能是更好的解决方案。 (虽然另一种选择是使用C ++,但只是避免使用依赖于此缺失功能的功能)
But the further out you get, the more abstractions and OS services and runtime libraries can be made available, and the more high level languages become suitable.
但是越远,您就可以获得更多的抽象和OS服务以及运行时库,并且更高级的语言也变得合适。
So C++ can be, and is used widely in operating systems. Just not at every level.
因此C ++可以在操作系统中广泛使用。只是不是在每个级别。
#3
13
If you visit osdev.org, you'll find that many people do in fact use c++ for OS development. In fact there are pages in the wiki specifically dedicated towards demonstrating the basics of doing so. Lots of hobbyist operating systems (my own included) are written in c++ with a decent degree of success as far as functionality goes.
如果你访问osdev.org,你会发现很多人确实使用c ++进行OS开发。实际上,维基中有一些页面专门用于展示这样做的基础知识。许多业余爱好者操作系统(包括我自己的)都是用c ++编写的,就功能而言,它取得了相当大的成功。
However, major operating systems such as windows, linux and osx were largely written before c++ was considered mature. It doesn't make sense to retrofit code to support a new language (though to be honest, it isn't difficult to get the majority of c++ supported in kernel land, exceptions and rtti are the only real annoyances).
但是,在c ++被认为是成熟之前,主要的操作系统,如windows,linux和osx。改进代码以支持新语言是没有意义的(尽管说实话,在内核领域支持大多数c ++并不困难,异常和rtti是唯一真正的烦恼)。
Some people may say that since it is not trivial to get rtti and exceptions in kernel land, then there isn't a large advantage to using c++. i disagree, c++ is a great language to use for kernel development. templates are an amazing tool, for writing efficient generic code. Even things such as a type safe linked lists are much easy to implement using c++ without the need for anything but templates. Also, many things in kernels are inherently an object oriented task, while you can clearly model these things with c well, why not use a language that more easily models them. These are just a few of the advantages.
有些人可能会说,因为在内核中获得rtti和异常并非易事,所以使用c ++没有很大的优势。我不同意,c ++是一种用于内核开发的优秀语言。模板是一个了不起的工具,用于编写高效的通用代码。甚至诸如类型安全链表之类的东西也很容易使用c ++实现,而不需要除模板之外的任何东西。此外,内核中的许多东西本质上都是面向对象的任务,而你可以用c清楚地模拟这些东西,为什么不使用更容易建模的语言。这些只是其中的一些优点。
#4
11
Question: "What new features of c++ do you think would make it possible to develop a faster or more secure or better optimized or <other cool feature> OS?"
问题:“您认为c ++的哪些新功能可以开发更快,更安全或更优化或 <其他酷炫功能> 操作系统?”
Second question: "What major OS has been developed since c++ really came of age?"
第二个问题:“自c ++真正成熟以来,开发了哪些主要操作系统?”
(Note that one possible answer is Be, which I think did use c++... Ah, wikipedia says the API was c++, which is not quite the same thing.)
(注意,一个可能的答案是Be,我认为它确实使用了c ++ ......啊,*说API是c ++,这不是一回事。)
#5
5
C++ used to be "c + new features". But that was a long time ago now. Of course, it depends to some extent on your C++ compiler, but the language has evolved and now contains important syntactical differences as well. "c + new features" over-simplifies the situation.
C ++曾经是“c +新功能”。但那是很久以前的事了。当然,它在某种程度上取决于您的C ++编译器,但语言已经发展,现在也包含重要的语法差异。 “c +新功能”过度简化了这种情况。
But your question premise is also mistaken - linux and OS X reportedly both have significant amounts of not only C code but also both C++ and raw assembly in them.
但是你的问题前提也是错误的 - 据报道,linux和OS X不仅有大量的C代码,而且还有C ++和原始汇编。
#6
2
Initially, C++ is not used for performance reason. At this point, all these OS have been developed on C + asm and rewrite to C++ to no one will. Also C++ is not so obvious as C. In particular because of this, Linus Torvals doesn't like C++. http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918
最初,C ++不是出于性能原因而使用的。在这一点上,所有这些操作系统都是在C + asm上开发的,并且重写为C ++,没有人愿意。 C ++也不像C那么明显。特别是因为这一点,Linus Torvals不喜欢C ++。 http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918
#7
1
As far as I know, almost all Haiku OS is made of C++ : http://en.wikipedia.org/wiki/Haiku_(operating_system)
据我所知,几乎所有的Haiku操作系统都是用C ++编写的:http://en.wikipedia.org/wiki/Haiku_(operatingratingystem)
#8
1
My understanding is that eCos was written entirely in C++ and provides C interfaces.
我的理解是eCos完全用C ++编写并提供C接口。
#1
18
The very short answer is that no entirely new operating systems of any significance have been created at all since C++ attained maturity in the late 90's. And using C++ is not, by itself, nearly a compelling enough reason to completely re-write an existing successful OS.
非常简短的答案是,自从C ++在90年代后期成熟以来,根本没有创建任何重要的新操作系统。并且使用C ++本身并不是完全重写现有成功操作系统的充分理由。
#2
18
C++ is used widely for operating systems. Big parts of Windows is written in it.
C ++广泛用于操作系统。 Windows的大部分内容都写在其中。
But the OS isn't one monolithic blob. There are different layers and components to it. A few bits and pieces pretty much have to be written in assembly, because there is no portable way to implement them: this is low-level handling of the CPU and other hardware, which is abstracted away in higher level programming languages.
但操作系统不是一个整体的blob。它有不同的层和组件。因为没有可移植的方法来实现它们,所以必须在汇编中编写一些零碎的部分:这是对CPU和其他硬件的低级处理,这是在更高级别的编程语言中抽象出来的。
Then there is a layer which can be written in a higher level language, but it just can't rely on other code. It provides a few basic services that are needed for the next layer, and so it has to just work on its own.
然后有一个层可以用更高级别的语言编写,但它不能依赖其他代码。它提供了下一层所需的一些基本服务,因此它必须独立工作。
C++ can be used there, but there are some limitations. C++ requires the runtime library to implement quite a bit of functionality (exception handling, for example), which might not be available (or which it might not be desirable to make available at that level), and so C may be a better solution there. (Although an alternative option is to use C++, but simply avoid features that rely on this missing functionality)
可以在那里使用C ++,但是有一些限制。 C ++要求运行时库实现相当多的功能(例如,异常处理),这些功能可能不可用(或者可能不希望在该级别提供),因此C可能是更好的解决方案。 (虽然另一种选择是使用C ++,但只是避免使用依赖于此缺失功能的功能)
But the further out you get, the more abstractions and OS services and runtime libraries can be made available, and the more high level languages become suitable.
但是越远,您就可以获得更多的抽象和OS服务以及运行时库,并且更高级的语言也变得合适。
So C++ can be, and is used widely in operating systems. Just not at every level.
因此C ++可以在操作系统中广泛使用。只是不是在每个级别。
#3
13
If you visit osdev.org, you'll find that many people do in fact use c++ for OS development. In fact there are pages in the wiki specifically dedicated towards demonstrating the basics of doing so. Lots of hobbyist operating systems (my own included) are written in c++ with a decent degree of success as far as functionality goes.
如果你访问osdev.org,你会发现很多人确实使用c ++进行OS开发。实际上,维基中有一些页面专门用于展示这样做的基础知识。许多业余爱好者操作系统(包括我自己的)都是用c ++编写的,就功能而言,它取得了相当大的成功。
However, major operating systems such as windows, linux and osx were largely written before c++ was considered mature. It doesn't make sense to retrofit code to support a new language (though to be honest, it isn't difficult to get the majority of c++ supported in kernel land, exceptions and rtti are the only real annoyances).
但是,在c ++被认为是成熟之前,主要的操作系统,如windows,linux和osx。改进代码以支持新语言是没有意义的(尽管说实话,在内核领域支持大多数c ++并不困难,异常和rtti是唯一真正的烦恼)。
Some people may say that since it is not trivial to get rtti and exceptions in kernel land, then there isn't a large advantage to using c++. i disagree, c++ is a great language to use for kernel development. templates are an amazing tool, for writing efficient generic code. Even things such as a type safe linked lists are much easy to implement using c++ without the need for anything but templates. Also, many things in kernels are inherently an object oriented task, while you can clearly model these things with c well, why not use a language that more easily models them. These are just a few of the advantages.
有些人可能会说,因为在内核中获得rtti和异常并非易事,所以使用c ++没有很大的优势。我不同意,c ++是一种用于内核开发的优秀语言。模板是一个了不起的工具,用于编写高效的通用代码。甚至诸如类型安全链表之类的东西也很容易使用c ++实现,而不需要除模板之外的任何东西。此外,内核中的许多东西本质上都是面向对象的任务,而你可以用c清楚地模拟这些东西,为什么不使用更容易建模的语言。这些只是其中的一些优点。
#4
11
Question: "What new features of c++ do you think would make it possible to develop a faster or more secure or better optimized or <other cool feature> OS?"
问题:“您认为c ++的哪些新功能可以开发更快,更安全或更优化或 <其他酷炫功能> 操作系统?”
Second question: "What major OS has been developed since c++ really came of age?"
第二个问题:“自c ++真正成熟以来,开发了哪些主要操作系统?”
(Note that one possible answer is Be, which I think did use c++... Ah, wikipedia says the API was c++, which is not quite the same thing.)
(注意,一个可能的答案是Be,我认为它确实使用了c ++ ......啊,*说API是c ++,这不是一回事。)
#5
5
C++ used to be "c + new features". But that was a long time ago now. Of course, it depends to some extent on your C++ compiler, but the language has evolved and now contains important syntactical differences as well. "c + new features" over-simplifies the situation.
C ++曾经是“c +新功能”。但那是很久以前的事了。当然,它在某种程度上取决于您的C ++编译器,但语言已经发展,现在也包含重要的语法差异。 “c +新功能”过度简化了这种情况。
But your question premise is also mistaken - linux and OS X reportedly both have significant amounts of not only C code but also both C++ and raw assembly in them.
但是你的问题前提也是错误的 - 据报道,linux和OS X不仅有大量的C代码,而且还有C ++和原始汇编。
#6
2
Initially, C++ is not used for performance reason. At this point, all these OS have been developed on C + asm and rewrite to C++ to no one will. Also C++ is not so obvious as C. In particular because of this, Linus Torvals doesn't like C++. http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918
最初,C ++不是出于性能原因而使用的。在这一点上,所有这些操作系统都是在C + asm上开发的,并且重写为C ++,没有人愿意。 C ++也不像C那么明显。特别是因为这一点,Linus Torvals不喜欢C ++。 http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918
#7
1
As far as I know, almost all Haiku OS is made of C++ : http://en.wikipedia.org/wiki/Haiku_(operating_system)
据我所知,几乎所有的Haiku操作系统都是用C ++编写的:http://en.wikipedia.org/wiki/Haiku_(operatingratingystem)
#8
1
My understanding is that eCos was written entirely in C++ and provides C interfaces.
我的理解是eCos完全用C ++编写并提供C接口。