Thread: why not ++?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158

    why not ++?

    I noticed that a lot of active projects (including higher level projects, not just OSes and such) use straight C. Why not C++? Converting a project would take almost no effort in most situations, provide future development with much more flexibility while still including the features of straight C, and I know everyone who knows C knows C++, it's basically just an extension, and as far as I know, C doesn't usually perform any better than C++. Why do some projects/people do this, what is there to gain?
    Thanks

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    >> Converting a project would take almost no effort in most situations, provide future development with much more flexibility while still including the features of straight C

    >> and I know everyone who knows C knows C++


    Attachment 10197

    >> Why do some projects/people do this, what is there to gain?


    Apparently your own time by not throwing out an entire code base just because it's not new while it is still well supported on platforms, and there are people alive who can write it; people who think C++ should replace C will stay out of your project and not cause drama.
    Last edited by whiteflags; 11-24-2010 at 07:35 PM.

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by whiteflags View Post
    [B]Apparently your own time by not throwing out an entire code base just because it's not new while it is still well supported on platforms, and there are people alive who can write it
    I use C code bases all the time with my C++ projects (sometimes even mix the two in one binary) with no problem, which is why I don't see how that's a reason.
    Quote Originally Posted by whiteflags View Post
    people who think C++ should replace C will stay out of your project and not cause drama.
    I'm not trying to say they should convert their projects - just saying that they could, negating it as a reason for using C over C++. Remember, I'm just wondering why one would choose to use straight C in the first place. (besides, I guess, not knowing C++ that well or at all)

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    >> I use C code bases all the time with my C++ projects (sometimes even mix the two in one binary) with no problem, which is why I don't see how that's a reason.

    Suppose it's appropriate to use some C code in a C++ project. Can you tell me if it is easier to wrap C++ around a C project or dump some new C into a new C++ project? Both languages still have idiosyncrasies, and I do not buy that the change is completely painless. Hell you probably have to rework several if not all of the dynamic allocations because C++ handles a separate heap in most implementations.

    It's always a complete rewrite. It's not always a deliberate choice to use C over C++, especially if this is not brand new code.

  5. #5
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    C is supposedly a little faster, I guess that's a reason. Anyway, what would they gain by hacking code meant for a .c into a .cpp, if all the code is still in a function-based form?

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by User Name: View Post
    C is supposedly a little faster, I guess that's a reason...
    That is not correct.
    C and C++ are tied for speed. C is better in some areas, C++ in others.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by Elysia View Post
    That is not correct.
    C and C++ are tied for speed. C is better in some areas, C++ in others.
    I don't really think you can say that one is faster than the other when the speed of the code depends on how well the compiler optimizes your code. It's really compiler vs. compiler.

    Computer Language Benchmarks Game reflects what you say, i.e. C is faster in only some areas, but take a look at the distributions...somehow C++ has a much, much smaller standard deviation. Since both languages end up as machine code in the end, it's apparent that g++ does a better job of optimizing than gcc.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Epy View Post
    I don't really think you can say that one is faster than the other when the speed of the code depends on how well the compiler optimizes your code. It's really compiler vs. compiler.

    Computer Language Benchmarks Game reflects what you say, i.e. C is faster in only some areas, but take a look at the distributions...somehow C++ has a much, much smaller standard deviation. Since both languages end up as machine code in the end, it's apparent that g++ does a better job of optimizing than gcc.
    No, it's not compiler vs compiler. It's about language features.
    For example, take the standard library sort. Now, run it, say, 10^9 times. In both C (eg qsort) and C++ (std::sort). Which will be faster? C++, hands down. No doubt about that.

    Now, take a hand-written, hand-optimized sort by a guru and compare it to C++'s std::sort. Run it 10^9 times. Which one wins? Probably C in this case.

    The thing is that there are some things--like templates--that allow C++ to do things that C cannot. But with C, you usually roll out your own optimized solutions for a specific case, and they are sometimes going to more efficient, giving C the trophy in this case. This could be done in C++, but usually isn't, because we want to achieve more genericism.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by Elysia View Post
    But with C, you usually roll out your own optimized solutions for a specific case, and they are sometimes going to more efficient, giving C the trophy in this case. This could be done in C++, but usually isn't, because we want to achieve more genericism.
    This can't be done in C since it doesn't share a relationship with C++, the same way C++ does with C. This is an advantage of C++, as indeed I can insert C code in my project and have that specific part be compiled by the C compiler, while the rest is dealt with by the C++ compiler.

    However these type of situations are mostly only for academics or for very specialized situations which don't represent the vast majority of programmers' concerns. More commonly we simply don't care which one is faster given that both languages offer a performance window that more than suits the vast majority of tasks.

    ... and as do many other languages. All the mainstream languages do, for sure.
    Last edited by Mario F.; 11-29-2010 at 07:57 AM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > and I know everyone who knows C knows C++,
    Erm, there's a huge chasm of knowledge between being able to write a C program that will compile with a C++ compiler and actually being able to write a GOOD C++ program with a meaningful class structure.

    Nor does the "meaningful class structure" emerge automatically, simply by renaming .c to .cpp.
    At best, it's an instant conversion of passable-to-good C into horrible C++. Any C++ native would instantly puke at the sight of it.

    As for being trivial, read this -> Incompatibilities Between ISO C and ISO C++

    > Remember, I'm just wondering why one would choose to use straight C in the first place
    Whoever started the project made a choice, based on what they knew and what they preferred.

    With only a little more syntactic hacking, you can turn C into Java. Hell, they both use curly braces and semicolons - it can't be that hard right
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Rewriting a good C code is pointless. You should leave the window open for re-writing bad C code in C++ instead of good C code though, if you are going to invest on the revising task.

    But there might be still a good reason to re-write good C code in C++ code, just changing it so it compiles with C++ compiler. Then you can continue a project in C++ and use the C code as it is. Using its functions or adding some lines in main. Yes, the code might look strange but still functionality is more important than looks. Of course you have to have a reason to want to use C++. Which might be some libraries for example.

    So you have a choice as an example. Continue in C and implement some C++ libraries you want in C or make the C code C++ compatible and continue in C++. The second I would say is a best strategy.

    Translating code to another language is a pain (i.e. from Java to C++). Continuing a code to another language might not be. The benefit of C to C++ is that you can use the C code as it with some changes and use C++ for the rest.

  12. #12
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by Salem View Post
    As for being trivial, read this -> Incompatibilities Between ISO C and ISO C++
    After reading through the first couple of parts, it looks to be more of a comparison of C90 with C99 than anything else. It looks like C99 upgraded C to a point that is mostly compatible with C++.

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    With only a little more syntactic hacking, you can turn C into Java. Hell, they both use curly braces and semicolons - it can't be that hard right
    ...or for that matter if you know Java you can turn it into C++ easily. After all they both use OOP and classes. Cannot count how many times I've heard that but have yet to find a Java programmer who has not touched C++ that can just start programming well in C++ from the word go.

    I seriously doubt I could code anything noteworthy in pure C. I have been spoiled by C++ and although I think I know what is supported in ISO C as compared to ISO C++ the journey would not be a pleasant one. Porting from pure C to good, meaningful, well-architected C++ would most likely require a project of its own and would not be a small undertaking.

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Hmmm... let me ask the contrary question... Why C++ ?

    Far as I can tell C is still a perfectly viable language.

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    C is old, and misses a lot of functionality that is critical to today's requiring applications.
    C is a language that is designed for platforms where the language must be easy, fast and cheap to implement.
    Today's applications simply require a lot of things that C cannot provide easily. Therefore C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed