LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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


View Poll Results: Which is better?
C 24 34.78%
C++ 35 50.72%
C# 2 2.90%
Other/Don't Care/Huh? 8 11.59%
Voters: 69. You may not vote on this poll

Reply
  Search this Thread
Old 04-12-2003, 01:30 AM   #16
iHeru
Newbie
 
Registered: Apr 2003
Distribution: Slackware 9.0 and Debian 3.0
Posts: 26

Original Poster
Rep: Reputation: 15

I program C++, so I have no experience with malloc/free, setjmp/longjmp or printf, for example.

I think knowing C++ w/o necessarilly knowing C is quite possible. There's a lot of overlap, but not everythings the same.
 
Old 04-12-2003, 08:29 AM   #17
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Quote:
Originally posted by jsimonelis
How is it that you can program in the superset of a language and not the base?
Well, if all you know is cout, for example, then you go to C and wonder how to print something out...

Sure, syntactically C++ is a superset of C, but the two languages typically use a totally different set of concepts and function calls.
 
Old 04-12-2003, 10:02 AM   #18
macewan
Senior Member
 
Registered: Jan 2002
Distribution: Ubuntu, Debian
Posts: 1,055
Blog Entries: 1

Rep: Reputation: 45
in school they gave us a c++ book and had someone try to teach it to us. she was not qualified to teach the subject. i kept the book. using it to teach myself.
 
Old 04-12-2003, 05:21 PM   #19
nakkaya
LQ Guru
 
Registered: Jan 2003
Location: Turkey&USA
Distribution: Emacs and linux is its device driver(Slackware,redhat)
Posts: 1,398

Rep: Reputation: 45
c++ is considered to be supset of c because it accepts c commands and sytax put c++ is total diffrent you do not have to learn c to master c++ cause c++ gives you all the tool avaible to get c strength
 
Old 04-13-2003, 02:03 PM   #20
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Quote:
Originally posted by wapcaplet
I didn't say they always did; I just said they tend to be smaller and faster. Obviously Bjarne Stroustrup is going to be a little bit biased In my experience, though, anything written in C compiles to a smaller binary. I haven't actually measured the speed myself, but there has to be a pretty good reason that almost all GNU-related development seems to be done in C, rather than C++.

Just now I tested it with a small program:

Code:
#include <stdio.h>
int main()
{
  printf("Hello, world\n");
  return 0;
}
Compiled it:


gcc hello.c -o helloc
g++ hello.c -o hellocpp
ls -l
-rw-rw-r-- 1 eric eric 75 Apr 8 17:12 hello.c
-rwxrwxr-x 1 eric eric 11346 Apr 8 17:17 helloc*
-rwxrwxr-x 1 eric eric 11450 Apr 8 17:17 hellocpp*


Trivial example, I know, but there ya go.
I don't think that a hello world program will tell you very much at all about speed or size of the executables because there is no inheritance or polymorphism used. In C++ you can use inheritance and polymorphism to collect generalized operations and attributes in a base class. In a family of classes the dependant operations are declared virtual in the base class, so that polymorphism will dynamically bind to the approapriate subclass operation. This saves a lot of code rewriting. In addition, if you have a widget set which you can inherit from, the design reuse is extensive. Also, with OOP you have decentralized control, which allows you to upgrade implementation to take advantage of encapsulation, in an action based design, the implementation is tied to a central data structure, from which changes can have wide ranging effect. These are just a few reasons why OOP is much better to work with. Java is an example of an OOP platform however the core language is weaker than Standard C++. Yet in Java you can see some of the advantages of using OOP.


Last edited by GtkUser; 04-13-2003 at 02:05 PM.
 
Old 04-13-2003, 07:29 PM   #21
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Quote:
Originally posted by GtkUser
I don't think that a hello world program will tell you very much at all about speed or size of the executables because there is no inheritance or polymorphism used.... (snip)
Point taken. Though I would imagine there is some penalty in terms of execution speed for all the dynamic binding that needs to be accomplished in C++ with polymorphism, inheritance, etc. Seems like this would be a case of balancing size with speed.

I personally would take C++ over C any day, though.
 
Old 04-13-2003, 09:59 PM   #22
CGuy
LQ Newbie
 
Registered: Apr 2003
Location: Canada
Distribution: Red Hat, SuSE, Gentoo
Posts: 5

Rep: Reputation: 0
I personally prefer C++ myself, it's my native language
C can be considered a subset of C++, as nearly all C programs can be compiled in a C++ compiler (though I haven't yet encountered one that doesn't).

With that said, C and C++ were both designed with different purposes in mind. C was originally designed for the purpose of creating operating systems, specifically, UNIX. Dennis Ritchie did a really good job with both his OS and his language. Meanwhile, C++ was designed at a time when C was found to be useful for much more than operating systems, and so was designed with a more general purpose in mind.

I prefer C++, most likely because much of my work involves creating data structures; I like to be able to create easy-to-use API's which I can do easiest using Object-Oriented programming techniques. If this thread is to be a debate on whether C or C++ is better, then the running theme should be about classic procedural vs. OO programming.

On another note: I noticed there's very little discussion about C#. I've had a good look at it myself; the idea behind it is interesting. C# was designed around Microsoft's .NET platform - one which is designed to make integration of software very easy. Remember COM+ objects? .NET was designed to solve many of the problems that COM+ had. C# cannot be discussed without at least a minimal understanding of how the .NET platform operates.

The .NET platform can be run on operating systems other than Windows; through both the open-source Mono project and Microsoft's "shared-source" ROTOR project. I saw a demonstration of the ROTOR project on FreeBSD; while it is nowhere near complete, it does show an effort on the part of Microsoft to be more platform independant.

.NET is not only for C#; it's available using VB, C++, J# (Microsoft's second legal attempt at stealing Java (Remember J++?)) and just about any other programming language you can think of. A nice feature is that the .NET base class library is uniform throughout each .NET language - the API is the same no matter what. This allows for much simpler cross-language compilation under .NET. And - .NET implements one feature which solves one of the major problems that plague both C and C++ - using the __gc modifier, you can make any object garbage-collected as in Java. No more messy memory leaks from trying to manage memory yourself.

C# has one nice feature which I like: safe/unsafe blocks. In C#, normally pointers are not allowed. However, if you declare your code as unsafe, then the compiler knows you have purposely used pointers, and will compile, as long as you compile with the /unsafe directive. This helps to ensure the safe usage of pointers.
 
Old 04-14-2003, 01:17 AM   #23
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
I'm still searching for a suitable Standard C++ widget set or API. So far, none exist.

As far as C# goes, I might have to take that course in school, but I don't want to use C# for anything, except to compare it with Java and Standard C++ for the research value. I think that Linux would benefit from a middleware system, and that there is no need for it to be compatible with C# or Java. Hopefully the core language would be more sophisticated than Java or C#, for example, it would support generic programming and a protected access modifier, and virtual and multiple inheritance, as well as operator overloading, generic algoritms, etc.

I would settle for a simple widget set that supported Standard C++, otherwise I have to write it all myself in a couple years from now, once I know more about programming.

Last edited by GtkUser; 04-14-2003 at 01:19 AM.
 
Old 04-14-2003, 01:35 AM   #24
macewan
Senior Member
 
Registered: Jan 2002
Distribution: Ubuntu, Debian
Posts: 1,055
Blog Entries: 1

Rep: Reputation: 45
c# required? is java being required in your school? if not could you tell us the name of the school?
 
Old 04-14-2003, 04:11 AM   #25
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
The network of Colleges is called Devry. I witnessed second hand, Microsoft seduce Devry into going 100% .Net and Microsoft. They were offering some Java2, but that is being replaced by C#. It all came down to money. Devry does not do it's own research and development. They were originally teaching C++ and C which is the domain of R&D, until they realized that they should have been teaching middleware which places R&D in the hands of the vendor. Now Microsoft is signing up students and giving them software bundles. Marketing .Net by brute force like only a monopoly can.

On an unrelated note, the Mono project < www.go-mono.com > is a good programming environment, however they shouldn't worry about making their middleware compatible with .Net, instead it should become a business platform for Linux or X11. It actually should not be compatible with .Net or Microsoft. I think that Linux should concentrate on it's own domain.
 
Old 04-14-2003, 04:37 AM   #26
macewan
Senior Member
 
Registered: Jan 2002
Distribution: Ubuntu, Debian
Posts: 1,055
Blog Entries: 1

Rep: Reputation: 45
I still think that because of Microsofts track record of trying to extract $ from anything that whatever is even remotely related to them is an extremely risky environment. This includes mono. Especially since this SCO/IBM situation came along. I just feel that MicroSoft will eventually try something to limit the mono project. Then all the mono followers will freak out saying it's not fair! They cheated! My feeling is that linux users should go with the java platform.

That's just my gut feeling.
 
Old 04-14-2003, 05:28 AM   #27
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Why would it matter if Mono was not compatible with Microsoft? I wish that it were NOT compatible, and that Linux had it's own middleware business platform.

I would settle for a Standard C++ toolkit but middleware that supported a more complete core language than .Net or Java2 would also be great. Why not learn from Sun's mistakes and borrow some ideas from .Net, and build a high quality virtual framework and IDE specifically for Linux. Why should we have to use vendor middleware, or model our middleware (mono) so that it is controlled by the biggest criminal organization on earth (Microsoft).
 
Old 04-14-2003, 06:38 AM   #28
cwolf
Member
 
Registered: Mar 2003
Location: Switzerland
Distribution: Sun Solaris 7/8/9, Fedora Core 3
Posts: 63

Rep: Reputation: 15
I think it depends on what kind of program you want to create. For a system-application C is the best choice. But for a GUI-Application C++ is better.
 
Old 04-14-2003, 01:45 PM   #29
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Standard C++ has no GUI library.
 
Old 04-14-2003, 03:12 PM   #30
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Corba has been around for ages, why .NET or Mono?! ;)

Back in the days when it (Corba) was written bandwidth
was one the draw-backs that made it ummmmmm, let's
say unwieldy... (and not overly well performing)

Now that everyone is using switches and/or Gigabit ethernet
and even a majority of home users has broadband MS
came up with something "completely new!" (yeah right...)
and gave it a massive hype...

Cheers,
Tink
 
  


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