what advantage does C has over C++?

Discussion in 'OT Technology' started by D1G1T4L, Jan 19, 2005.

  1. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    better question is probably, in which situation or where would you use the C programming language over C++ ?
     
  2. Shibboleth

    Shibboleth teh mad Plato skillz

    Joined:
    Sep 29, 2004
    Messages:
    1,769
    Likes Received:
    0
    C is the language C++ was built on, any "C" is effectivley part of C++. There is no real advantage of using C over C++. It would be bad programming practice to purposfully avoid using C++ code in favor of C. The only people I know who refuse to use any C++ are stuborn people who were brought up on C and just don't think it's worth it.

    Honestley there's nothing that C can do that C++ can't or vise versa, but the advantage C++ provides is making a programmers life easier (now debuggers, that's a different story. It's much harder to debug C++ then it is to debug C). C++ will generally use less lines of code.
     
  3. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,419
    Likes Received:
    593
    I've read that pure C (well-written) is generally faster than C++, but it's harder to write.
     
  4. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    It really depends on the application. Low-level things like operating systems where speed and such matter are usually written in pure C. C++ is actually just the object-oriented extension of C, so anything where using OOP isn't viable or necessary would use C rather than C++.
     
  5. adam17

    adam17 now im gonna sing the doom song! doom doom doom do

    Joined:
    Aug 25, 2004
    Messages:
    1,666
    Likes Received:
    0
    Location:
    n ur gf's bed
    i think C is a little more portable than C++, but thats only something i have heard :dunno:
     
  6. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    C++ has a standard just like C. For the most part, the mainstream C++ compilers adhere to the standard, and any discrepancies will eventually be worked out.

    From a design standpoint, if you have a trivial one man project where you don't expect much future growth or maintenance, then C would probably work as well as C++. But, for larger projects, starting with a good object oriented design can reduce the likelihood of future headaches when it comes to maintenance, design updates, new features, etc. One of the more powerful features of C++ is that you can express and enforce many design constraints in the code itself. A well thought-out design in C++ can prevent future coders from going astray and wasting time debugging their code. Something that's difficult or impossible to do in C.
     
  7. shiba kesaigi!

    shiba kesaigi! New Member

    Joined:
    Dec 6, 2004
    Messages:
    8,442
    Likes Received:
    0
    Sorry.
    but the answer is
    None.
     
  8. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,419
    Likes Received:
    593
    Sorry, but you're wrong. Or do you think the fact that device drivers are written in C rather than C++ is a coincidence?
     
  9. SL1200MK4

    SL1200MK4 New Member

    Joined:
    Sep 27, 2003
    Messages:
    1,552
    Likes Received:
    0
    Well, there are many situations where even if you use C++, your program isn't really very OO like at the end.

    Especially when it involves lots of system call, fork, threads.
     
  10. kl

    kl New Member

    Joined:
    Sep 19, 2004
    Messages:
    94
    Likes Received:
    0
    Embedded systems. C can be very useful for microcontrollers or very low level microprocessor applications. In these applications, it parallels assembly. What's really cool is you can write a C program with inline assembly code. The idea being you don't have any rules to follow except the rules that have been specified for the device and what it does. Object oriented programming just doesn't have a place there.

    I always hated C classes because we were writing C++ for unix systems. Once we started getting into mircocontrollers, I really enjoyed it. Probably because I'm a Comptuer Engineering major.
     
  11. MrMan

    MrMan New Member

    Joined:
    Jul 13, 2004
    Messages:
    308
    Likes Received:
    0
    If you write a simple hello world in C and C++, the C executable is much smaller. Imagine a C and C++ code for a huge application that does the same thing. C++ promotes object oriented code. As somebody said, C is also faster. But most C coders moved on to C++ and some C++ coders moved on to C#. Is it worth knowing... yes. If you had to learn just one... learn C++.
     
  12. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    thanks for all the replies
     
  13. RSXTypeWTF

    RSXTypeWTF teh best n00b evar

    Joined:
    Jul 13, 2002
    Messages:
    317
    Likes Received:
    0
    C++ does a lot of magic for you behind the scenes that C will not. I like C because there is very LITTLE magic. One thing you can do if you're on a UNIX system is compile some code with C++ linking and compile some code with C linking ie

    /* SAMPLE_HDR_H */

    #ifdef __cplusplus
    extern "C" {
    #endif

    /* Your declarations/fcn prototypes here */

    #ifdef __cplusplus
    }
    #endif

    If you place those guards and examine your code with nm or something that can extract symbols from object files you'll find in C it's nice and clean. In C++ it does all this mangling/stores the object ID and other crap. But my other gripes? Generic programming in a strictly typed language? The way it handles multiple inheritance...hell, when asked about iostream, the writers said in retrospect they should not have used multiple inheritance. C++ just seems like a language full of constructs "just because."

    I hear OO in python is good. You could couple C with python and get good results. The only other OO I've done is in Java. ;(
     
  14. logan

    logan vacantskies

    Joined:
    Jan 7, 2005
    Messages:
    589
    Likes Received:
    0
    Location:
    Eureka, CA
    I say, if you were looking to learn programming in either, head over to C#. C# is the future.
     
  15. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    There's no magic. Name mangling is just a way to make things such as overloaded functions, templates, namespaces all possible using a simple linker. You may have a valid gripe if your job is to write a C++ debugger, but for everyone else, why does it matter? Fear of the unknown shouldn't be an excuse to disparage a very powerful tool.
     
  16. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    C# is only the future of Microsoft programming. Most device drivers and other low-level programs (OSes, etc) are still written in plain old C, and most programs on OSes other than Windows are written in C++.
     
  17. RSXTypeWTF

    RSXTypeWTF teh best n00b evar

    Joined:
    Jul 13, 2002
    Messages:
    317
    Likes Received:
    0
    I'm not disparaging what I don't know, I'm disparaging what IS unknown. Large C++ applications (I've had to work in a few) are a lot like large perl (a horrible maintenance nightmare) applications, albeit for different reasons. The C++ ones simply becomes overly complex in its abstractions. The magic I was referring to is ridiculous side effects that may occur. Static initialization fiasco familiar? (Refer to the C++ FAQ Lite for that) I've had that subtle bug crop up before and if I can't tell when my constructors are going to get called/initialized if that's not magic, what is it? Or ridiculous operator overloaded methods. You can blame the programmer all you want but why didn't they just restrict certain fundamental ones like +/-/* to const qualified objects. Don't get me started on the grammar. C++ has a few shift/reduce reduce/reduce conflicts on its plate...

    Going back to having constructs "because." Do function style typecasts REALLY help??? :confused:

    I've had my share of C++ dev time. The only API I use now that has a real C++ base is Qt, which isn't half bad I suppose. OpenGL, SDL, et. al. have a real C feel to them. An alternative? OO with the familiar C syntax? I hear Obj-C is pretty good, but I haven't had time to work with it... :wtc:

    The biggest advantage of C over C++ in my eyes is clarity. If you need to do some OO, find some scripting language and bind it with C to do your heavy lifting.

     
    Last edited: Jan 21, 2005
  18. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    i am learning C++ (been like 5 years since i touched it), i can always go back and look over C and pick up bad habits from it ;)
     
  19. Shibboleth

    Shibboleth teh mad Plato skillz

    Joined:
    Sep 29, 2004
    Messages:
    1,769
    Likes Received:
    0
    I want to correct my earlier post and say that c is usefull for programs that must be very small and very fast. Also it's helpful to know if you're going to help in any open source projects.
     
  20. shiba kesaigi!

    shiba kesaigi! New Member

    Joined:
    Dec 6, 2004
    Messages:
    8,442
    Likes Received:
    0
    no the drviers after 1999. go check it again.
     
  21. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    You don't know what you're talking about.
     
  22. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
    Even though Objective C is a true superset of C, I think it is quite a bit different from C or C++. It is a very weakly typed language, though some may argue that C or C++ are somewhat weakly typed as well. Objective C has a smalltalk message style format, like this:

    [myCar setSpeed:10 seats:4 gas:12.0];

    I'd suggest programming on a Mac if you want to learn Objective-C.
     
  23. Penance

    Penance Guest

    C has no advantages over c++, nor would i use it in any instance over C++:nono:

    i suppose C maybe a little more leniant with minimul erorrs, but that not a problem really

    thing is the developers made C++, from C too create an easier way of learning the language, i think theyin fact made it harder..... ne ways thats just IMO
     
  24. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,419
    Likes Received:
    593
    C++ wasn't made to be easier to learn, it was to extend C and make it better, more powerful, and object-oriented.

    And C does have advantages - that's why it's still widely used for OS programming.
     
  25. Jericho

    Jericho Active Member

    Joined:
    Oct 21, 2002
    Messages:
    34,140
    Likes Received:
    0
    python > *
     

Share This Page