LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 09-16-2004, 04:09 PM   #1
Burgin
Member
 
Registered: Apr 2004
Posts: 54

Rep: Reputation: 15
Question C and C++ side-by-side examples


Does anyone know of any books with identical programs with one side showing a C example and the other showing the C++ equivalent? I like to be able to have an idea of the right way to do something in each as opposed to mishmashing the two.
 
Old 09-17-2004, 02:51 AM   #2
suowei1979
LQ Newbie
 
Registered: Sep 2004
Location: BeiJing,China
Distribution: Red Hat
Posts: 25

Rep: Reputation: 16
As I know,NO
 
Old 09-17-2004, 03:27 AM   #3
javeree
Member
 
Registered: Jun 2004
Location: Belgium
Posts: 49

Rep: Reputation: 15
I even think this would not be very instructive at all, because if used right C++ is not just 'C with classes stuck on it'. C++ is meant for object oriented programming, which -if done right- results in a completely different approach of problems than when doing functional programming.
Of course, you could try to mimic all the features of C++ by hand (actually the fiorst C++ compilers did just that: translate C++ in C-code that mimics the approach), but these kind of programs would then be way too complex to understand and maintain.

The trcik is to use the right tool for the right job. If you want to write a "hello world" program, there is no reason to do it in C++, because it'l be much faster in C. If you want to write a component-based architecture, use C++ because it supports the problem domain better.
 
Old 09-17-2004, 11:14 AM   #4
Burgin
Member
 
Registered: Apr 2004
Posts: 54

Original Poster
Rep: Reputation: 15
"I even think this would not be very instructive at all"

I suspected that what I wanted would be kind of controversial. Your view (javeree) is probably consistent with Bjarne Stroustrup who probably would not approve either. I'll just say we all learn differently.

Learning just what is the right tool for the right job to me, means seeing one attempt to use two different tools to accomplish the same task. The differences between C anc C++ are not quite as easily to ascertain as the differences between a hoe and plow.

Now that I remember, I think there was a magazine called "c/c++ journal", or something another, that did show side-by-side code listings.

Last edited by Burgin; 09-17-2004 at 11:16 AM.
 
Old 09-17-2004, 01:08 PM   #5
mungulish
Member
 
Registered: Aug 2004
Location: Hungary
Distribution: Debian, OpenSUSE
Posts: 33

Rep: Reputation: 15
The side-by-side comparison might not be a bad idea, but I wouldn't advise it. You could turn out to be a great C , but an awful C++ programmer. There might be one solution, a book from Bjarne Stroustrup: The C++ Programming Language Special 3rd Edition. It explains the main advantages of C++ , and the C++ solutions for C styles. If you read it you, won't need a side-by-side comparisons, which are sometimes wrong.
For example, I would write the "Hello,world" example, almost the same. How would you write templates in C, I'm not saying it can't be done, but it would be one wild comparison.
C++ is not strictly OO. A good C++ programmer only uses classes when there's reason. For example, in the book Stroustrup uses sturcts instead of public Classes.

But it's your choice...
I think there's a weekly journal at

www.cprogramming.com
 
Old 09-17-2004, 01:42 PM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
C++ template question

Doh! Ignore my post. I meant to hit the new thread link, not reply to...

Last edited by deiussum; 09-17-2004 at 02:04 PM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
PSU - which side up?! lrt2003 General 5 11-13-2004 04:47 AM
server side jhon Linux - Networking 1 09-01-2004 11:59 AM
help with client side NFS-firewall setup and server side NIS-firewall setup niverson Linux - Networking 3 02-02-2004 08:52 AM
Side Buttons Gman22 Linux - Software 5 08-12-2003 03:16 PM
That thing to the side InsaneBob Linux - Software 2 06-22-2003 05:33 PM

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

All times are GMT -5. The time now is 01:53 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