PDA

View Full Version : Is c++ a better c?



dark
02-06-2003, 05:42 AM
hi,
Could someone ans this for me its bugging me for a long time.

Is c++ a better c? If so why is c still being used? Tell me some uses as well.

please help.

Magos
02-06-2003, 05:52 AM
In one sentence:

C++ adds some nice features, at the cost of some performance.

Polymorphic OOP
02-06-2003, 05:57 AM
That's all a matter of opinion. In my opinion, it's an "of course it is." However, you will find some people who will disagree.

Why?

C++ is basically C but with a whole bunch extra. Just about anything you can do in C++ as well, even using the same syntax (in most cases), however C++ offers better type checking and an incredible amount of more built-in functionality.

One of the reasons C is still used a lot is because it's a hell-of-alot easier to make a C compiler than it is to make a C++ compiler. All of it's functionality is fairly low-level (for a high-level language).

C++, on the other hand, has a LOT more than that. On top of all that C has, it introduces of an entire new paradigm of programming. There is so much to the language of C++ that it's a lot more difficult and takes much more time to create a compiler for it than for C, and even still, there are very few compilers that can claim nearly 100% compliance to the C++ standard.

In short, most of the people who think think C++ isn't a better C think so because they feel that a simpler language is an easier to understand language is a better language (which actually ends up being quite the opposite on large-scale applications). It all comes down to opinion, though I feel very strongy, yes, c++ is definately a "better c" (and much much more than that).

Polymorphic OOP
02-06-2003, 06:01 AM
Originally posted by Magos
C++ adds some nice features, at the cost of some performance.

I'd have to disagree with that to some extent. You can use the "C features" of C++ and get the same or better performance than of C (depending on the compiler). And when it comes to using member functions, it's potentially just as fast as passing the address of a structure in C. When it comes to virtual functions, you have to take into account the fact that in order to get similar functionality you'd have to either make your OWN vtable (which would give you most-likely the same, or less speed), or you'd have to set up enumerated values, etc.

In actuality, c++'s "C features" are potentially just as fast and there's no reason they can't be faster. It's impossible to compare the higher level features of C++ to C because there is no direct correspondence between functionality, however, if you tried to simulate the functionality in C manually, your results would most-likely be slower than that of a C++ compiler.

PawelK
02-06-2003, 06:05 AM
I started with C++ but after a while I changed to C because it is easier to understand and you can do all the same things like with C++(with C it take longer to write the same program, but the code is also easier to understand then the C++ code with classes and the other things)

Travis Dane
02-06-2003, 08:13 AM
Originally posted by PawelK
I started with C++ but after a while I changed to C because it is easier to understand and you can do all the same things like with C++(with C it take longer to write the same program, but the code is also easier to understand then the C++ code with classes and the other things)

I don't know wich tutorial you've taken, But C++ can accept
C code, So you can just program C++ without classes and such
you don't understand.

Cela
02-06-2003, 11:21 AM
>>Is c++ a better c?
In my opinion, big yes.

>>If so why is c still being used?
If there are so many better languages out there, why is FORTRAN still being used? :-)

Govtcheez
02-06-2003, 11:30 AM
> So you can just program C++ without classes and such
you don't understand.

Then you've thrown away the biggest bonus for using C++ in the first place.

Travis Dane
02-06-2003, 11:37 AM
Originally posted by Govtcheez
> So you can just program C++ without classes and such
you don't understand.

Then you've thrown away the biggest bonus for using C++ in the first place.

I know, But he said he wen't programming C while he just
could've stuck with C++ and just don't use C++ features he
doesnt understand, I dont get it.

Polymorphic OOP
02-06-2003, 05:06 PM
Originally posted by Govtcheez
> So you can just program C++ without classes and such
you don't understand.

Then you've thrown away the biggest bonus for using C++ in the first place.

And you are left still with C++'s

Better type-checking
Templating
More expansive standard library (if you're okay with USING objects and just not creating classes)
Upgraded ?: operator
And a bunch more!

Sure classes are [arguably] the biggest bonus (some might say templating is), but there are still other reasons one would use c++.

Shiro
02-07-2003, 11:23 AM
>Is c++ a better c? If so why is c still being used? Tell me some uses as well.

I don't think one of the two is best. C is still used a lot, for example in embedded systems development.

Terrance11
02-07-2003, 11:29 AM
Originally posted by dark


Is c++ a better c?.

Yes, of course, it's a superset of c (mostly a superset for those of you who might jump on me for not adding that). OOP and STL is what's going to allow programmers progress in the future while the size of programs continuously grows.


Originally posted by dark
If so why is c still being used? Tell me some uses as well.

C++ is (in a lot regards) a different language. Old time C'ers may stick with what they like, rather than using C++.

100% pure c may still be using in embedded systems programming, or in other instances that speed is a factor, but even c++ has taken over a considerable amount in those areas.

Another reason C is still being used is legacy code. C'er's will always be needed in that sense.

But as programs get more complex (and they always will), c will continue to be used less and less.

Since most application in c/c++ are windows programs, I can't see many coding in windows api for large scale projects for the future, which would force many c'ers to start moving into C++/MFC.

And I don't even want to get into the business aspects of why c++ would be used over c, but as you can all tell, I'm a c++'er :)

But those are just my opinions, I know I've been shot down for promoting c++ before, but I feel I'm correct.

Sorry, but I'm anti- C. (not C++!)

ammar
02-07-2003, 11:56 AM
dark, when you ask that type of questions, you should always keep in mind that what might seem better to you, might be worse to some one else.
I think you should've asked, what is the difference between C and C++? And that question have been answered many times.

dark
02-13-2003, 05:15 AM
Originally posted by ammar
I think you should've asked, what is the difference between C and C++?

ammar i didn't want to know the difference between C and C++.
i think i did ask the right question and got the answers i needed. thankx for suggesting.


thankx everyone especially Terrance11(got a lot of info from you).

ammar
02-13-2003, 07:20 AM
BTW: I think if you are asking to determine what language you are going to learn, you can simply learn both of them, because it's not difficult to learn one when you already know the other.

dark
02-13-2003, 09:02 PM
Originally posted by ammar
BTW: I think if you are asking to determine what language you are going to learn, you can simply learn both of them, because it's not difficult to learn one when you already know the other.

I have nearly finished learning C. I wanted to know whether I needed to learn C++ as well.
looks like i do so i am going to.


Can you suggest any good book for C++. It dosen't have to be easy to understand but should be to the point.

ammar
02-14-2003, 06:04 AM
Since you have a good backgroung in C, you can try a book called: C++ the programming language, by stroustrup( the one who designed and implemented the C++ programming language ), I think it's a good book for you.

Fordy
02-14-2003, 06:31 AM
Originally posted by Polymorphic OOP
I'd have to disagree with that to some extent. You can use the "C features" of C++ and get the same or better performance than of C (depending on the compiler). And when it comes to using member functions, it's potentially just as fast as passing the address of a structure in C. When it comes to virtual functions, you have to take into account the fact that in order to get similar functionality you'd have to either make your OWN vtable (which would give you most-likely the same, or less speed), or you'd have to set up enumerated values, etc.

In actuality, c++'s "C features" are potentially just as fast and there's no reason they can't be faster. It's impossible to compare the higher level features of C++ to C because there is no direct correspondence between functionality, however, if you tried to simulate the functionality in C manually, your results would most-likely be slower than that of a C++ compiler.

I would have to say that I aggree with Magos......there are certain inclusive features of C++ that can impose a slight overhead. RTTI for one....exceptions for the other ( - this is more due to compiler vendors not focussing optomisation on this subject - and why should it? - optomisation on error handling is hardly a must!)...and as operator new should throw bad_alloc on a failure, you should be prepared to take the hit (even though it is tiny IMO).

Some compilers allow you to turn off these features...but they are still parts of the language and covered by the standard...

I must say though that I have never found any of C++ to be a burdon and I use it all the time..its a matter of perspective and its usually only newbies or the narrow minded that use this as an argument to promote C over C++......I never bother with straight C - I prefer C++

Polymorphic OOP
02-14-2003, 06:36 PM
Originally posted by Fordy
there are certain inclusive features of C++ that can impose a slight overhead. RTTI for one

That only comes into play when you are using polymorphism, which isn't even supported in C. You can't really say it's slower because there is nothing to compare it to in C. This was what I was refering to in my previous reply when I said it's not really valid to compare it to C in this particular respect because in order to get similar functionality in C, you'd have to create your own vtable or something similar, which would most-likely end up being slower at runtime than using polymorphism directly in C++.


Originally posted by Fordy
....exceptions for the other ( - this is more due to compiler vendors not focussing optomisation on this subject - and why should it? - optomisation on error handling is hardly a must!)...

True, though I do agree with you that the "hit" is so tiny and only comes into play in certain circumstances that it's not something one would argue much about.


Originally posted by Fordy
and as operator new should throw bad_alloc on a failure, you should be prepared to take the hit (even though it is tiny IMO).

Yeah, but if you really were concerned you could always just use malloc in C++.