LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-05-2016, 12:44 PM   #16
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124

Quote:
Originally Posted by sundialsvcs View Post
Using C++ in this highly-specialized context would bring uncertainty, headaches, and really, no particular advantage.
Using "C with classes" would seem to offer some advantages even without the C++ libraries.
 
1 members found this post helpful.
Old 02-05-2016, 12:51 PM   #17
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by sundialsvcs View Post
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 View Post
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 View Post
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 View Post
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.
valid for the Linux kernel, not for say haiku, where the kernel is written in C++, for example look at
https://cgit.haiku-os.org/haiku/tree/src/ in general
https://cgit.haiku-os.org/haiku/tree/src/system/kernel in special
 
Old 02-05-2016, 09:35 PM   #18
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by a4z View Post
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 View Post
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".

Last edited by psionl0; 02-05-2016 at 09:37 PM.
 
Old 02-06-2016, 12:53 AM   #19
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by psionl0 View Post
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".
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.
 
Old 02-06-2016, 05:18 AM   #20
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by a4z View Post
. . . 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.
 
Old 02-06-2016, 06:46 AM   #21
Captain Pinkeye
Member
 
Registered: Oct 2012
Location: The Czech Republic
Posts: 280

Rep: Reputation: 98
Quote:
Originally Posted by psionl0 View Post
Yes, the kernal has been written in C but that doesn't mean that it couldn't be written in C++
It could, technically.
Quote:
...nor that C++ couldn't be used in future upgrades.
Considering Linus' stance on C++, very unlikely..
 
Old 02-06-2016, 07:53 AM   #22
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
(It is hard to argue with LT, for two reasons: 1. he is practically a troll 2. he is actually a programmer who knows what he is talking about.)
 
Old 02-06-2016, 10:21 AM   #23
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by psionl0 View Post
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.
 
1 members found this post helpful.
Old 02-06-2016, 10:41 AM   #24
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by a4z View Post
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.
All of that I agree with.
 
Old 02-06-2016, 07:59 PM   #25
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by Captain Pinkeye View Post
Considering Linus' stance on C++ programmers, very unlikely..
ftfy.
 
1 members found this post helpful.
Old 02-06-2016, 08:28 PM   #26
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
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.
 
1 members found this post helpful.
Old 02-07-2016, 01:19 AM   #27
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by sundialsvcs View Post
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.
 
Old 02-16-2016, 02:30 AM   #28
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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.
 
Old 02-16-2016, 03:14 AM   #29
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by bigearsbilly View Post
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.
 
Old 02-16-2016, 07:52 AM   #30
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration