LinuxQuestions.org
Help answer threads with 0 replies.
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-16-2016, 07:57 AM   #31
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930

Why not use C and C++ for a parallel experiment and make your own determination?

In the end it's all about the code and how the compiler interprets it.

And that's actually the first thing I learned about C. Bunch of engineers, we were using C long before our employer decided we all needed to take an advanced class in it.

Funnily enough the instructor was a (pardon the phrase) cocky Engineer just like all of us. He challenged us minute number one to expel our prowess, and explain to him all we knew about the C language and tell him all we knew about how good versus bad it was compared to assembly.

Well, he may as well have either worked directly with Kernighan and Ritchie, or literally been those guy. He was the equivalent of a compiler designer. And his first and recurrent point was that the most important thing for us to work at understanding was:
Quote:
Know how the compiler interprets what you write.
He hammered that the whole week. And to me, it doesn't matter how good versus bad C and C++ compare, even C# or also Objective C. If you're concerned about efficiency, speed, and memory footprint, then what you need to understand is the code which is generated based on what you wrote and how you wrote it. There are tons of prama, or preprocessor directives as well as compiler switches, and then there are tons of systems which these compilers are built for. If you wish to tune your code to be highly efficient for a particular case, then you need to get under the hood of what code is being generated by the compiler and also where it is being located in your system.
 
Old 02-16-2016, 08:12 AM   #32
jross54000
LQ Newbie
 
Registered: Feb 2016
Posts: 9

Rep: Reputation: Disabled
Use C for systems programming. Use C++ for application programming. It's that simple. Anyone who says otherwise has probably never done systems programming.
 
Old 02-16-2016, 09:00 AM   #33
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by jross54000 View Post
Use C for systems programming. Use C++ for application programming. It's that simple. Anyone who says otherwise has probably never done systems programming.
Quote:
Originally Posted by sundialsvcs View Post
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.

you did not read what was written, otherwise you would meanwhile know that there is more than 1 OS where also kernel / driver , or what you called system programming, is done in C++.
but thanks for your expert opinion, especially those who say to have done system programming an know therefore all about it
 
Old 02-16-2016, 09:30 AM   #34
jross54000
LQ Newbie
 
Registered: Feb 2016
Posts: 9

Rep: Reputation: Disabled
Fair enough. I'll qualify the statement by saying that in Linux, C is much more efficient as a systems programming language. C++ contains layers of abstraction that make it a better choice for application programming.
 
Old 02-16-2016, 09:33 AM   #35
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I've always said that you can write very much C-like C++ code. That is because C++ is a C extension language. I've seen lots of drivers written in C++.

We get a lot of embedded toolkits based on C++.

Tons of arguments one way versus another as to whether or not using libraries in embedded systems are things people do.

Some say it depends if the library was well tested, if they have accessibility to source, and if it's a commercial library. Others say "no way" write it your self so you know what the code is doing.

Same for systems code.
 
Old 02-16-2016, 05:55 PM   #36
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Encapsulation, inheritance and polymorphism would seem like very good reasons for using C++ in a large project (which I would classify a Linux kernel as).

However, these are about the only features of C++ that you would be able to take advantage of if you wish to maintain absolute control over the code that is produced. Even the exception handling provisions of C++ might seem off-limits. (Where are the exception variables stored? What sort of error trapping code is produced?)
 
Old 02-17-2016, 12:46 AM   #37
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
Encapsulation, inheritance and polymorphism would seem like very good reasons for using C++ in a large project (which I would classify a Linux kernel as).

However, these are about the only features of C++ that you would be able to take advantage of if you wish to maintain absolute control over the code that is produced. Even the exception handling provisions of C++ might seem off-limits. (Where are the exception variables stored? What sort of error trapping code is produced?)
interesting how different opinions can be

I would say that inheritance and polymorphism are less important than RAII + destructor guarantee for resource management, and of course the possibility of templates, which, used correct and with caution, add extra type security instread of some macro void* constructs.

inheritance and polymorphism is 90 % used wrong or in a overdose, and that's the point where people care more about solving their inheritance diagram than solving the real problems.
not mentioning that real 'is a' relations are less likely than the java 'A implements B' relation which is mostly nonsense in C++ to implemnent via Interfaces but used everywhere.

exceptions are optional. the advantage is they can not be ignored and help to have a useful interface that does not disable things like for example copy elision.

Code:
Data a = getData() :
// terminates if fails
is simply a better interface, it runs faster since return value optimization and more secure than

Code:
Data a ;
int ret = getData(&a);
// forgotten check ret to terminate if no 0
// undefined behaviour
 
Old 02-17-2016, 09:47 AM   #38
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
inheritance and polymorphism is 90 % used wrong or in a overdose, and that's the point where people care more about solving their inheritance diagram than solving the real problems.
not mentioning that real 'is a' relations are less likely than the java 'A implements B' relation which is mostly nonsense in C++ to implemnent via Interfaces but used everywhere.
I hear you. Too many people think that just because it is possible to do "clever" things in C++ that they have to - even when done in a stupid way. Maybe that's why Linus wants to boil C++ programmers in oil.

Quote:
Originally Posted by a4z View Post
exceptions are optional. the advantage is they can not be ignored and help to have a useful interface that does not disable things like for example copy elision.
I am aware of the usefulness of exception handling. I'm just not convinced that their use would still allow a programmer to retain absolute control over all memory use/allocation. (I could be wrong about that though).
 
Old 02-19-2016, 12:34 AM   #39
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
for the system programming has to happen in C folks,
https://sourceware.org/ml/libc-alpha.../msg00416.html
enjoy!
 
Old 02-19-2016, 01:36 AM   #40
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Quote:
Originally Posted by a4z View Post
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.
I rarely use void actually. So no, I haven't given up type safety. Whatever you think that may be.
I don't copy code snippets, that's hard work, I generally create shared libraries and use a lot of dynamically loadable plugins for your information.
(If I did though I would call them "design patterns" :-)

Granulation? Don't get that bit. I didn't copy from the internet I made it up as a half joke actually.
A bit like "Java.lang.out.of.bloody.memory.again "

You C++ programmers take your language far too seriously.

edit: oh yes, I never use macros either. It's not 1995 you know.

Last edited by bigearsbilly; 02-19-2016 at 01:59 AM.
 
Old 02-19-2016, 02:48 AM   #41
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 rarely use void actually. So no, I haven't given up type safety. Whatever you think that may be.
I don't copy code snippets, that's hard work, I generally create shared libraries and use a lot of dynamically loadable plugins for your information.
(If I did though I would call them "design patterns" :-)

Granulation? Don't get that bit. I didn't copy from the internet I made it up as a half joke actually.
A bit like "Java.lang.out.of.bloody.memory.again "

You C++ programmers take your language far too seriously.

edit: oh yes, I never use macros either. It's not 1995 you know.
please show me you dynamic array implementation that works for which type/struct ever.
without, what you say do , macros, void* , repeat yourself ( = copy past)
 
Old 02-19-2016, 07:11 PM   #42
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
for the system programming has to happen in C folks,
https://sourceware.org/ml/libc-alpha.../msg00416.html
enjoy!
I'm not sure what your point is. Is it that there is a bug in some software that was written in C or that had the language of choice been C++ then this bug could not have happened?
 
1 members found this post helpful.
Old 02-21-2016, 04:11 AM   #43
genss
Member
 
Registered: Nov 2013
Posts: 744

Rep: Reputation: Disabled
edit: nvm, i don't care

Last edited by genss; 02-21-2016 at 05:32 AM.
 
  


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 08:57 AM.

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