Thread: why not ++?

  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,613
    >> 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,613
    >> 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
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.

  7. #7
    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.

  8. #8
    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.

  9. #9
    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.

  10. #10
    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.

  11. #11
    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.

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Elysia View Post
    Today's applications simply require a lot of things that C cannot provide easily. Therefore C++.
    Ok... such as?

    Seriously... what can you do in C++ that I can't do in C?

    (Other than "Objects" or "Classes", that is.)
    Last edited by CommonTater; 11-26-2010 at 12:22 PM.

  13. #13
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by Yarin View Post
    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
    Frankly? Because there are more mediocre programmers out there than there are talented ones. When the former group is tasked with creating safe, portable, and well-designed C++ code, they fail. Simple as that...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by CommonTater View Post
    Ok... such as?

    Seriously... what can you do in C++ that I can't do in C?

    (Other than "Objects" or "Classes", that is.)
    That's the point. Objects, abstraction, encapsulation, generic.
    It's not that you can't do it, but it quickly becomes a nightmare to manage.

    Try coding a large game in C. Oh, it's possible, but it's probably not going to be easy.
    But the thing is that modern programming languages makes it easier.

    We could also argue about security. C is a very unsafe language by default. Oh, it's certainly possible to write code safely, but it isn't always trivial and once in a while, you make mistakes.
    Higher-level languages reduces this risk and thus creates fewer bugs in the longer end.
    This is a statistical example.
    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.

  15. #15
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Elysia View Post
    That's the point. Objects, abstraction, encapsulation, generic.
    It's not that you can't do it, but it quickly becomes a nightmare to manage.

    Try coding a large game in C. Oh, it's possible, but it's probably not going to be easy.
    But the thing is that modern programming languages makes it easier.

    We could also argue about security. C is a very unsafe language by default. Oh, it's certainly possible to write code safely, but it isn't always trivial and once in a while, you make mistakes.
    Higher-level languages reduces this risk and thus creates fewer bugs in the longer end.
    This is a statistical example.
    Your points all seem to orbit around "easy", "fast" and such. Having spent a lot of time in Pascal, which is "mid level" like C++ I get all that... but what kind of program can be written in C++ that can't be written in C?

    I don't want to compare programming skill...
    I'd like to see an honest comparison of the capabilities of the languages...

Popular pages Recent additions subscribe to a feed