ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hate to bust-up your shouting match here but ... most of the gcc compiler suite really doesn't care what the source-language is! Whether it's C, C++, Fortran, COBOL, or what-have-you, the source language gets transformed into an intermediate format (ASTs, etc ...), and object-code is produced from that.
hm, yes
Quote:
Originally Posted by sundialsvcs
At runtime, C++ programs make very heavy use of "standard libraries," provided as a part of the compiler system. (glibc is the most well-known of these.) Many of the features that are "built in" to C++ are, in fact, implemented by these libraries. Naturally, a lot of attention has been given to the task of "optimizing the hell out of" these.
in C++ you do not pay for something that you do not use, nothing is added by magic.
either you include it as code that is generated or you decide to link agains, if you don't you dont have it in the binary.
Quote:
Originally Posted by sundialsvcs
The problem, with respect to system programming, is that the kernel environment is Spartan: the environment that is expected by these libraries does not exist, and cannot be used by kernel code. For example, in kernel-land you cannot call printf(). At all. The kernel provides a simplified message-formatter, but that's part of the kernel itself.
yes, this is language agnostic and the Linux kernel requires C but no C libraries functions that do not exist in kernel space,
that's why I said use C where you have to, but this is a design decision, not a god given rule
Quote:
Originally Posted by sundialsvcs
Much of the handling of "objects," also, is done through library functions ... therefore, "not available here." And, on top of that, in kernel-land it is extremely important to know exactly what is being done (on multiple hardware platforms!) when a particular source-language statement is being executed. Using C++ in this highly-specialized context would bring uncertainty, headaches, and really, no particular advantage.
in C++ you do not pay for something that you do not use, nothing is added by magic.
either you include it as code that is generated or you decide to link agains, if you don't you dont have it in the binary.
Quote:
Originally Posted by a4z
yes, this is language agnostic and the Linux kernel requires C but no C libraries functions that do not exist in kernel space,
that's why I said use C where you have to, but this is a design decision, not a god given rule
Don't those statements contradict each other?
There should be no problem writing efficient Linux kernel code in C++ provided it doesn't use any library functions "that do not exist in kernel space".
There should be no problem writing efficient Linux kernel code in C++ provided it doesn't use any library functions "that do not exist in kernel space".
I see no contradiction, yes it should be possible to write efficient Linux kernel code in C++, as you do it for other operation systems, but common sense is to use C for Linux since the design decision was taken.
. . . common sense is to use C for Linux since the design decision was taken.
Arguments that start with "common sense" tend to raise the hairs the back of my neck. Yes, the kernal has been written in C but that doesn't mean that it couldn't be written in C++ nor that C++ couldn't be used in future upgrades.
The end result should still be the same but the judicious use of classes could reduce the incidence of bugs or difficult-to-track programming errors.
Arguments that start with "common sense" tend to raise the hairs the back of my neck. Yes, the kernal has been written in C but that doesn't mean that it couldn't be written in C++ nor that C++ couldn't be used in future upgrades.
The end result should still be the same but the judicious use of classes could reduce the incidence of bugs or difficult-to-track programming errors.
well, if you clip away what was in front that you of course miss that I not only basically agree with you that C++ for a kernel is possible but also show examples where it is used. And I also always say that C++ is not just as efficient but also a saver choice, of course only for those who understand how to use it correct.
And there are also posts from me in such discussions that mention that the destructor guarantee is a great thing and I would not want to live without it.
But bad programmers wirte also bad and buggy code in C++, so even if I agree that is is much simpler through RAII and destructor to produce error save and secure code, in practice I see less code bug free/reduced through the choice of the language than through the choice of the developer team doing the tasks.
well, if you clip away what was in front that you of course miss that I not only basically agree with you that C++ for a kernel is possible but also show examples where it is used. And I also always say that C++ is not just as efficient but also a saver choice, of course only for those who understand how to use it correct.
And there are also posts from me in such discussions that mention that the destructor guarantee is a great thing and I would not want to live without it.
But bad programmers wirte also bad and buggy code in C++, so even if I agree that is is much simpler through RAII and destructor to produce error save and secure code, in practice I see less code bug free/reduced through the choice of the language than through the choice of the developer team doing the tasks.
In all of the various operating systems whose guts I have explored (in very considerable depth, BTW ...), "kernel space" necessarily plays by very different rules from the comfy-cozy "user land" that it creates. Furthermore, as in the case of Linux, it quickly becomes architecture/model specific. In other words, the programmers who work on the thing really have to k-n-o-w exactly what sort of object-code is being produced. I'm rather of the opinion that C++ would "get in the way" more than it would be beneficial to the present effort ... and that switching all or part of the code base to it would be a business-risk impossible to justify.
I'm rather of the opinion that C++ would "get in the way" more than it would be beneficial to the present effort ... and that switching all or part of the code base to it would be a business-risk impossible to justify.
Considering that nobody has noticed that I said, "judicious use of classes", you are probably right.
I gave up C++ 4 years ago and went back to good old C. Since then I am much more productive.
The hidden benefits are:
1. I don't give a damn about template meta programming.
2. And I couldn't care less what a pure virtual friend base destructor pointer to member-function private protected pointer reference is.
Last edited by bigearsbilly; 02-16-2016 at 02:32 AM.
I gave up C++ 4 years ago and went back to good old C. Since then I am much more productive.
The hidden benefits are:
1. I don't give a damn about template meta programming.
2. And I couldn't care less what a pure virtual friend base destructor pointer to member-function private protected pointer reference is.
ad 1) so you gave up type safety by using void* all over the place combined with the macros everyone loves, or by simply copy and past the same code snippets just with different types, however not an improvement at all, no teven a hidden one.
ad 2) granulation that you are able to copy from the internet, even if the sentence makes non sense at all, but if proves your trolling attempts, which are, of course, of very low quality. If your train hard you next trolling attempt may become better.
Ladies, gentlemen, let's not insult one another with words like "troll." It's impolite, at best.
The purpose of C++ was to extend the C language to give it object-orientation. (The first C++ was a source-code preprocessor which emitted C output.) It could well be argued that it has since gone overboard ... as did ADD 1 TO COBOL GIVING COBOL.
When you are writing an operating-system kernel, running in kernel space and on an unpredictable architecture, I think that you really do need the precise control that C mixed with asm{ ... } gives you. You need to know at all times exactly what the source-code you are writing will translate into. You are writing to a very spartan environment. You are writing for a very specialized purpose.
In user-land, C++ might be a very efficient way to write source-code because it lets you write less, and because it improves the ability of the language to detect spelin errurs, things that in are the wrong place, and things that you simply lef ... But it would get in the way in the kernel project.
There's really no issue of efficiency: the back-end of the gcc suite is very heavily optimized for all of the architectures for which it runs. Every source-language that you feed into it becomes more-or-less the same stuff when it goes to the back-end to become object code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.