LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-19-2021, 05:47 AM   #1
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
C or C++?


Hi all,
I'm about to embark on a programming tutorial involving C. And...I was wondering...since I understand the concepts of OOP (Java)...should'nt I just learn C++ instead?
The software has to run on a Linux system and pretty dep down in the layers too...at the DE level, in fact...
So..C or C++?
Is (for example) XFCE written in C or in C++?
Thanks
Melissa
 
Old 07-19-2021, 07:18 AM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,600

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546
Quote:
Originally Posted by ButterflyMelissa View Post
The software has to run on a Linux system and pretty dep down in the layers too...at the DE level, in fact...
That's not deep? Some DEs use Python or JavaScript.

Quote:
So..C or C++?
Is (for example) XFCE written in C or in C++?
What do other people use for the desktop environment you're targetting?

If that's Xfce, check the relevant repositories.

If you don't have a reason to use a different language to everyone else, then do not.


Last edited by boughtonp; 07-19-2021 at 07:20 AM.
 
1 members found this post helpful.
Old 07-19-2021, 07:22 AM   #3
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
If you're thinking of writing Gnome/GTK apps (XFCE uses GTK), then C.
If you want to get all historic and investigate the native X11 libraries: libXaw, libXt, libX11/xcb, those are also C.

Ultimately, the choice will depend on what your end goal is. Besides, no reason not to learn both C and C++.
 
1 members found this post helpful.
Old 07-19-2021, 07:46 AM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Keep in mind that you'll likely be working with libraries that are written in C and meant to be used to be used in C.

A quick glance at GitHub says that Xfce4 is written in C.
 
Old 07-19-2021, 08:36 AM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
If the tutorial is in C, then you should consider sticking with C. That is if I understand that point correctly, which is that you're going to follow a programming tutorial that already has been worked out? If so, then whatever language they use, you should continue with.

Yes, some DE's use C++, like Qt and FLTK, I guess GTK uses C, from seen above, I do not know.

But hey ... if you know Java, and more pointedly OOP, then I feel you know C++.

You can't go wrong by learning C, and C++ is a superset above it.

As to what XFCE is written in, I do not know.
 
Old 07-19-2021, 09:24 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
No learning is wasted time, but let's note that C++ is still under intensive development, albeit it is already Huge (with capital H).
 
Old 07-19-2021, 10:45 AM   #7
khyym
LQ Newbie
 
Registered: Mar 2021
Posts: 1

Rep: Reputation: Disabled
Hi, I'm an ignorant but for me the answer is: "both and much more"; c and c++ always on the desk, it and it's history it's philosophy and it's people push up you to the intellectual glory.

From the lambda calculus to the stars!
 
Old 07-19-2021, 11:03 AM   #8
EdGr
Member
 
Registered: Dec 2010
Location: California, USA
Distribution: I run my own OS
Posts: 998

Rep: Reputation: 470Reputation: 470Reputation: 470Reputation: 470Reputation: 470
For your programs, I recommend writing largely in C style, but compiling with C++. This will let you selectively use the C++ features that improve upon C.

A C++ program can call C libraries as though nothing had changed.
Ed
 
Old 07-19-2021, 11:21 AM   #9
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
Swap "or" with "and!"

"Should I learn C?" Yes. "Should I learn C++?" Yes. (And I'd go on to say: "Should I learn ____?" Yes. Languages are, after all, "the tools of your trade." Studying new languages is a bit of a "nerd hobby" for me.

The C language was designed to be "better than assembler." The original Unix operating system was mostly written in it, and that's why it was invented in the first place. (Of course, so was Linux.)

C++ was originally implemented as a preprocessor which emitted C source code. The language implements many useful object-oriented features, but by doing so it "steps away from assembler." This for example is why the Linux kernel is not written in it. But, if I needed to write a binary program today, C++ is most likely to be the trusty hammer that I'd reach for, and recommend.

So, go ahead and take that course in "C." Next, take a similar course in "C++."

Last edited by sundialsvcs; 07-19-2021 at 11:25 AM.
 
Old 07-19-2021, 11:44 AM   #10
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,574
Blog Entries: 19

Rep: Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452
Quote:
Originally Posted by sundialsvcs View Post
This for example is why the Linux kernel is not written in it.
istr that Linus has a low opinion of C++.
 
Old 07-19-2021, 12:43 PM   #11
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
There are technical reasons (like ABI) to not write OS kernels in C++. They don’t apply if you’re writing desktop apps.

Last edited by dugan; 07-19-2021 at 12:54 PM.
 
Old 07-19-2021, 03:17 PM   #12
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
C++ programs, like most programs, are very dependent on a "runtime library" for their successful operation, and many of C++'s goodies are implemented using it. The language implementation also tacitly assumes that it is "running in userland."
 
  


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 09:34 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