When should we use C over C++ ?

Pages: 12
Hello everyone :)

What are the cases when we should use C or Assembly over C++ ?
That's a simple question, we want to know the answer :)

Waiting for you :)
closed account (zvRX92yv)
Resource Intensive loops when we don't want to waste any clock cycles. (Assembly)

For example, look up GIMPS, you'll see what I mean. :)

Not sure about C though.
Last edited on
C over C++? C++ is derived from C and adds OOP, don't see why you'de use C over it except for perhaps slightly less overhead...
Use C if you want a good reason for using macros, printf, c-style casts etc.
closed account (zb0S216C)
Read this: http://stackoverflow.com/questions/520068/why-is-the-linux-kernel-not-implemented-in-c

Wazzak
you should not compare C with C++, as Mr. Bjarn Stroustrup said:
C language is deprecated

it's similar as asking what should I use XP or windows7...
XP is history.

same with C.
you should not compare C with C++, as Mr. Bjarn Stroustrup said:
C language is deprecated


What a ridiculous thing to say - and to quote. More people program in C than in C++.

So, when would you use C over C++. I'm a C++ programmer so I'm not too sure, but I do think that C is more suited to a style that results in very efficient programing, as well as dealing with hardware elements where everything is void*. Of course, you can replicate the style in C++ - just as you can replicate the OOP aspects of C++ in C.


closed account (zb0S216C)
C doesn't have as much overhead as C++, such as virtual tables, inheritance, and operator overloading. Since C cuts all of the latter out, there's less to go wrong and bumps up the efficiency which makes is some-what faster.

If I was faced with this choice: "If C or C++ was to be destroyed, which would it be?", I would definitely choose C++. Why? If C was destroyed, so would C++.

C is a pleasant language to work with - hands-down; no questions asked. You get the feeling that there's nothing in your way as encapsulation does.

Wazzak
@exiledAussie
I'm a C++ programmer so I'm not too sure but I do think that C is more suited to a style that results in very efficient programing


I don't think so....
...C++ is far more advanced than old C.

More people program in C than in C++.


LOL that doesn't mean C is better than C++ dude.
more poeople is using C more that C++ only because of old programs wroten in C...
C++ is far more advanced than old C


True - but not the point. Something can be more advanced without being suited to a particular style. It is noticable when you use C APIs how bare the code is.

that doesn't mean C is better than C++ dude


True ;)
Though there is something to be said for writing old style C... it makes you very aware of how the machine works.

I think Framework is spot on.
closed account (zb0S216C)
codekiddy wrote:
I don't think so.... (sic)

How much experience have you had with C?

codekiddy wrote:
...C++ is far more advanced than old C. (sic)

That maybe the case, but without C, C++ is nothing.

codekiddy wrote:
LOL that doesn't mean C is better than C++ dude. (sic)

I beg to differ. If C++ is the better language, why are there more people using C? I, for one, am one of them. Have you ever considered portability? C++ is no where near as portable as C code.

Wazzak
Last edited on
I would say almost never use C over C++. Probably only if you are forced to by the environment you are writing in.

C++ is just as fast as C if you use the same features, so if you need the speed of C you have it without needing to use a C compiler.

To be honest I think the more relevant question might be when would you avoid using OOP techniques in favour of low level procedural code. Device drivers spring to mind. But even then, some OOP features can still be appropriate.


Framework wrote:
C++ is no where near as portable as C code.

That's interesting. I only write for Linux so I have not had portability issues. Can you provide some examples of standard C++ features that are non portable?
Can you provide some examples of standard C++ features that are non portable?
Advanced C++ features are at various levels of implementation in different compilers. This renders these advanced features non-portable.

One should remember C++ was written to solve specific problems with C. By throwing out C++ because some esoteric feature turns out not to be implemented in some vendor's implementation is no reason not to use the language.
thanks guys for interacting :)
so, as I conclude there is no reason to use C over C++ :)
Thank you so much :)
I see you are an wise and smart person :D
I'm happy that your conclusion point's forward and *NOT* back into history!
closed account (zb0S216C)
crazy frag wrote:
so, as I conclude there is no reason to use C over C++ (sic)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>

void SelfDestruct(void);

int main()
{
    SelfDestruct();
    return(0);
}

void SelfDestruct(void)
{
    printf("What a bad generalization :/");
}


Wazzak
Use C if you wish to write a program that is:
1. platform portable
2. programmer portable

1. C compilers exist for enormous number of platforms, while C++ compilers exist only for a limited number of some popular (mostly PC) platforms. For many exotic platforms (e.g. embedded or mainframes), if you are lucky, the only thing you get is some prehistoric build of GCC, that is far from standard compliant. So, probably you might be able to program C with classes, but not with STL and Boost. If you don't believe me, check Mozilla portable C++ programming guide - you will be shocked, which C++ constructs you are *not* allowed to use. Similar things at Google or IBM.

2. It is easy to find a C programmer, it is easy to understand C code. It is easy to maintain C code. You have a C project - just hire C programmers and you are done - they can immediately start hacking. You can learn C in a month or less. On the other hand, high level C++ programmers are incompatible with each other. They know (and use) different subsets of C++, and C++ is huge enough, that the number of useful subsets is enormous. Just ask a C++ programmer, whether constructors may throw exceptions or not, or whether you should use sharedptrs or not and you get a 40 post-long debate. They also tend to implement things in extremely compicated ways, just to get a virtual 5% performance improvement[1]. I pretty much understand why Linus Torvalds wanted to keep them away from Linux kernel.

[1] http://www.johndcook.com/blog/2011/06/14/why-do-c-folks-make-things-so-complicated/
Last edited on
@Framework

There are boost libraries for C++ which does the same thing and even more, no need for C headers.

edit:
C libs are here only because of support to tons of old programs wroten in C
Last edited on
That's a question I have, if C++ only has C libraries for reverse compatibility, what's the point? Can't people just use C compilers?
Pages: 12