C vs C++

Pages: 12
http://www.daniweb.com/community-center/geeks-lounge/threads/383422/what-would-win-in-a-fight-c-or-c

cwarn23 wrote:
I vote for C because C++ was written in C there for is limited to C's capabilities and is there by more recourse hungry than C as it another level of compilation of computer interpretation for reading the binary sequence. Things were sooo much simpler with punch cards.


First, C has no capabilities it is limited to. It is Turing complete. The first C++ compiler was probably written in C, but the C was then compiled into the machine's native code, so technically, it was run in the machine's native code, not C. Probably a mix-up about C++ being a superset of C.

Anyone agree? Any cons at all C++ has that C doesn't? (More keywords, so your variable names are more limited.)
Last edited on
I think C++ is better. C is actually when tested out SLOWER than C++ and C++ does have new functions and can do stuff that C cant.

I don't want to start a firewar or anything, but STRONGLY sugest you move to C++. It is the standard language for gaming and regular programming, and if you want a job as a programmer, you are DEFINITELY going to have to learn it.
Thanks for listening
-dean:)
Last edited on
Well, yea. I was, frankly, getting mad at the person who voted for C, and I couldn't find any good arguments they raised. "C Hacker Syndrome," maybe. :)
As pointed out in the thread- there are situations in which C is better. But you're right that that particular argument was kind of silly.

Although:

First, C has no capabilities it is limited to. It is Turing complete.


That IS a limitation.
Last edited on
Just to be completely sure we're on the same page here, how is being Turing Complete a limitation?

And yes, I have heard there is the occasional case where C is better. One would think C++ is strictly better than C, due to being an (almost) superset of C, but there was something about some areas where a good C++ compiler doesn't exist yet, but a good C one does.

James Kanze wrote:
Among the things that you can do in C, but not in C++, are:

-- not declare external functions, then call them with the
wrong number or type of arguments,

-- assign a void* to a typed pointer, regardless of type, with
no explicit conversion to warn you that something extremely
dangerous is going on.


(from http://www.velocityreviews.com/forums/t641348-is-c-only-better-c.html )

I laughed.

I'd also argue that C and Objective-C being (pretty much) supersets of C (I thought D was, too, at one point, but I probably got that mixed up with Objective-C) makes comparing them with C the only valid comparison without any sort of context. (Technically, no, they're not strict supersets of C, but they're pretty darn close.)
Last edited on

-- not declare external functions, then call them with the
wrong number or type of arguments,
-- assign a void* to a typed pointer, regardless of type, with
no explicit conversion to warn you that something extremely
dangerous is going on.


I'm pretty sure that you can't do that in C99 nor C1x, and even before those any decent compiler would've given you a warning (with the option to treat it as an error).

And of course Turing-completeness isn't a limitation per se, but in the case of C++ we have Turing-equivalence which is.

Oh, and if you're writing C code you're writing C code, independent of whether you're compiling with a C, Obj-C or a C++ compiler. Just saying.
Last edited on
c and c++ are designed for different purpose

in strictly critical real time embeded system development , c is always better than c++;

lukecian wrote:
c and c++ are designed for different purpose


True ... but with few exceptions, C code is valid C++ code, and does the same thing.

lukecian wrote:
in strictly critical real time embeded system development , c is always better than c++;


Just to be sure, do you mean runtime or time that it takes to develop? For how long a program takes to run, a lot more effort has gone into C++, so I'd claim that C++ is faster. For development time, again, C code is valid C++ code, and I find C++ much simpler, at the cost of having more keywords and such.
In the end, programs run on machines. Most of the time with a (modified) harvard architecture that caches data and instruction access. To get full speed, you need to avoid cache misses as much as you can. And once you do that, your code ends up looking like C no matter what language you write it in (well, and C code starts looking like assembly).

lukecian wrote:

in strictly critical real time embeded system development , c is always better than c++;


Nonsense. Incidentally our company does embedded programming in C++ and personally I can't think of _ANY_ reasons why C should be better suited for this purpose than C++, the only exception being if there isn't a decent C++ compiler available on the platform you're coding for.

Well to be silly, if C and C++ were actual people and fought each other in a battle C++ would win. C++ has the abilities of C in it and then augmented enhancements (the C++ features). So C++ would expect everything C could do and use the new abilities to destroy C.

More on topic, it really doesn't matter as you can't really compare any language to another language for one fact. Every language was designed for a specific reason or purpose which makes them all different even if they pull their syntax behaviour from another language.
closed account (o1vk4iN6)
The only C++ feature I think personally C++ has an advantage over C are templates. Some features like virtual classes can be implemented in C, although it won't be pretty it is still possible. C++ just standardizes it and hides it from the user. So in some situations, such as programming a compiler, it'll be easier to create a C compiler than a C++ compiler because of said wonderful features.

Pick the right tool for the right job. Some programming languages are specialized to do specific takes. If you try to make a programming language do too much it becomes too complex to program in and thus will have no user base. The argument of C being faster than C++ or vis-versa is irrelevant, go argue with the people saying Java is faster than C/C++. Point being with how fast hardware is the difference in speed is so minute it doesn't matter at the application level on PC's anyways (note: android uses Java, although they hacked on C/C++ [ note: horribly supported ] cause of performance issues for some things).

OpenCL/Cuda > C/C++ (read: flops)
Last edited on
The only C++ feature I think personally C++ has an advantage over C are templates. Some features like virtual classes can be implemented in C, although it won't be pretty it is still possible


Anything C++ does can be implemented in C, even templates (typically the same thing is done with macros in C). Yeah it isn't pretty, but it's possible.

Drawing a line for templates and nothing else is rather arbitrary.

Generally speaking, comparing languages is a waste of time. Comparing languages based on what it can do is an even bigger waste of time because all turing complete languages can do everything. What you're really comparing is how the language does it.
closed account (o1vk4iN6)
Well said, although templates are also turing complete. I don't think it's possible to use the preprocessor for meta programming, this is something that cannot be replicated in C, to my knowledge. I'd be happy if you can prove me wrong though, can always learn something new.
Last edited on
xerci wrote:
The only C++ feature I think personally C++ has an advantage over C are templates. Some features like virtual classes can be implemented in C, although it won't be pretty it is still possible.


And what about RAII? I find it really hard to take seriously any language that doesn't offer such a trivial but immensely powerful thing. I'd hate be forced to adhere to something silly like single-entry, single-exit just because the language doesn't offer me a simple, reliable way of telling the compiler to "do-this-on-scope-exit".

Also, how is the fact that C++ supports runtime polymorphism NATIVELY not an advantage?

Disch wrote:

Generally speaking, comparing languages is a waste of time. Comparing languages based on what it can do is an even bigger waste of time because all turing complete languages can do everything. What you're really comparing is how the language does it.


No, it's not. I hear that said a lot, but it's not. If language A and B both support feature X in some shape or form but language A makes it easy and straight-forward whereas language B makes you jump through hoops then language A is quite simply superior in that particular aspect.
Whovian wrote:
[quote=James Kanze]Among the things that you can do in C, but not in C++, are:

-- not declare external functions, then call them with the
wrong number or type of arguments,
[/quote]
How is that an advantage? It just shows how bad C is!
@antred:

When deciding on a language for a specific task, examining the language's strengths and choosing which one is best for the task is worthwhile. I agree with that.

But the general theme with these threads are "which language is better", which is a fruitless debate because each language has its own strengths and weaknesses.
closed account (3TXyhbRD)
Hello,

Don't forget that besides templates, C++ offers try... catch statements. Ofc you can emulate that mechanism with line tickets and some goto's in C, however line naming can be problematic from one point.

Like it was said, C was designed for one thing and C++ for another. C was designed to rewrite Unix, it also is a really good tool for programming servers where C++ is not, it doesn't even have sockets, you need to use C sockets (ofc using the respective OS libraries, but still they are from C and not made object oriented in C++). Same goes for IPCs.

Usually, you compare two languages to know which to use in a given context.
For instance, when you're programming a microprocessor you won't be using C++, you will be using C (given that the producer offers a library where you have a few functions implemented for you to use and not get in assembly stuff, even if you have to write assembly stuff you will still probably end up in C code rather than C++).
If you're designing an application with lots of features we see these days, you will be using C++ (or other object oriented languages) since OOD makes life much more easier and any design pattern is harder to apply in C than in C++. You can bypass C's structured form and make "objects" and emulate almost anything C++ has, but still it's not meant for that.

C vs C++ = win - win scenario, they're both excellent tools and very good for what they're designed to do. Trying to know only one of them (even if C is included in C++) in an attempt to learn less and it's a fools quest. Emulating C++ in C is rubbish for a real application (but a good programming exercise), using only C++ stuff is limiting because of above statements (sockets, IPCs, fork etc.). Using a C, C++ combo may prove a lack of knowledge between the both (horrible for a professional, but acceptable for a beginner).

Just my tuppence worth,
Good day!
LilJoe wrote:
C was designed to rewrite Unix, it also is a really good tool for programming servers where C++ is not, it doesn't even have sockets, you need to use C sockets (ofc using the respective OS libraries, but still they are from C and not made object oriented in C++). Same goes for IPCs.


You're using a C library. You're not necessarily writing C just because you use a C library. Writing a server in C++ is perfectly viable and, I find, a heck of a lot easier and less error-prone than doing the same in C.
C++ offers try... catch statements. Ofc you can emulate that mechanism with line tickets and some goto's in C
I don't think you can. You can simulate the transfer of control, but you can't simulate the management of objects and dealing with the error class hierarchy. OpenSSL has an extensible error hierarchy in C for example, but you can't handle the error at the level of your choosing.

C was designed to rewrite Unix, it also is a really good tool for programming servers where C++ is not
That's an interesting perspective. Can you explain why you think this is the case?

it doesn't even have sockets, you need to use C sockets
The sockets library is written in C because Unix is written in C. The sockets library does have an OO design, but because C doesn't support OO, the burden is pushed back onto programmers to enforce, making it difficult to use.

For example, you wouldn't expect to use send/recv with a UDP socket, but there's nothing to stop you making the call. A decent C++ sockets library will not have send/recv methods on a UDP socket, eliminating that kind of error. And all this extra type checking doesn't have a run-time cost.

Same goes for IPCs.
Agreed, same argument for sockets goes for IPCs.

Clearly features like templates generate more code and the exceptions require a more complicated run-time environment. So there's a price for some things, some things like Classes for implementing abstract data types with RAII is free.
Pages: 12