Thread: C, C++ difference - getting confused

  1. #16
    Registered User
    Join Date
    Apr 2013
    Posts
    5
    Quote Originally Posted by manasij7479 View Post
    I can't see any difference.
    There is no standard "GNU/Linux software packages", just a bunch of distinct projects .
    And Android's user space for Linux, other than the few components they did not bother to reinvent , is almost entirely written in Java.
    You need to get over the mentality that something can be written only in C.
    OK I don't think you need to be telling me what I need to do. When I write software for myself I mostly use python (and sometimes Matlab for maths) and C++ so I'm far from the idea that everything is in C .

    There is no GNU software packages? Sure there are - Software - GNU Project - Free Software Foundation. There's a reason they are listed on that website.

    I don't care about Android - sorry. What google and various other people have written on top of C is of no concern to me atm.

    So most of the GNU software is written in C (with obvious exceptions such emacs...but emacs is not a package - it's a platform of it's own).

    But even thinking about other languages - Python - why the hell did they implement this in C and not C++?

  2. #17
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    But even thinking about other languages - Python - why the hell did they implement this in C and not C++?
    Probably because Pyhton was conceived before C++ was standardized.

    So most of the GNU software is written in C
    Yes. But several parts are being converted to C++, the gnu compiler for example. But gnu is not the only game in town either. There are quite a few packages that are written in C++ available.

    with obvious exceptions such emacs...but emacs is not a package
    Why are you making an exception of emacs? It is also a package.

    Jim

  3. #18
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by s5s View Post
    But even thinking about other languages - Python - why the hell did they implement this in C and not C++?
    the obvious reason is portability. as was said earlier. not all platforms have C++. it's also likely that the creators of python were just more comfortable in C, and equally likely that C++ was not a mature enough language when python was created.

  4. #19
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    So most of the GNU software is written in C (with obvious exceptions such emacs...but emacs is not a package - it's a platform of it's own).
    Emacs is written with C, although not entirely. Many Lisp implementations are written in a similar way; the interpreter, compiler, and basic syntax and procedures are done in C and the rest in Lisp.

    But even thinking about other languages - Python - why the hell did they implement this in C and not C++?
    Preference. You'll probably get a better answer from the developers of CPython than anyone on here, so you might consider asking them on their mailing list or IRC channel (if they have those.) With that said, there are other Python implementations like JPython which are written in Java, so there's no requirement for it to be written in C or anything, and one could certainly be written in C++.

  5. #20
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by s5s View Post
    1. Is C still gaining popularity or is it being replaced by C++?
    That varies over time. C and C++ are both popular languages. New people are taking them up. Some people are transitioning from using other languages to C or C++. Some people are even transitioning from one to the other.

    Add other mainstream programming languages into the mix, and the normal ebb and flow of people learning new things, and the popularity of all programming languages changes over time. Sometimes the popularity (as a percentage of people programming) of any specified programming increases, sometimes it decreases. There is no programming language that is used by 100% of the programming community, and very few languages (esoteric or not) with a non-existent programmer base.

    I do not consider that C is being replaced by C++, or vice versa. Both have an active developer community, and both are used to address real-world problems. There is a significant number of C developers who won't touch C++, and a significant number of C++ developers who won't touch C. There is a significant number of people who use both, depending on the job at hand. Since a large part of C is technically part of C++, there is some confusion (among more people than will admit to it) due to people believing they are programming in C or C++, when in reality they are programming in some hybrid of the two.

    Quote Originally Posted by s5s View Post
    I know a lot of projects and code out there is in C simply because a stable C++ compiler was only released about 10-15 years ago whereas a stable C compiler has existed for a while.
    That's a really old excuse. In early days of C++, compatibility with C was leveraged to build its usage. Part of the political pushback against that, by C developers who did not want to see their numbers eroded, was to claim that C++ compilers were less mature, less stable, more resource hungry, and things like that.

    Part of the early problem with acceptance of C++ was that some of those claims were true, or had significant elements of truth, at the time.

    People who are pushing that line today, however, are way out of date. The quality of compiler technologies has improved and matured considerably. Both C and C++ compilers have improved as a result, and the claims are no longer true for either language. Both C and C++ are general purpose languages, and it is possible to list advantages and disadvantages each has over the other, depending on the task at hand. There are also many tasks where C and C++ are equally applicable, and the choice between them comes down to human (developer, management, etc) preferences.

    Quote Originally Posted by s5s View Post
    2. What is the niche that C is supposed to fill and that C++ is less suited for?
    C was originally designed as a system programming language, with the virtue that it could get "close to the machine". C++ was primarily designed around supporting higher levels of abstraction, which means a lot can be done with a relatively small amount of code.

    Since then, C and C++ have each evolved. C is still "closer to the machine" than C++ is, and C++ supports more abstraction than C does.

    The evolution of C (after the 1989 standard) has introduced more features for getting "close to the machine", but also supports higher levels of abstraction than earlier versions of C did. C++ has evolved mainly in the direction of supporting more abstractions, but the original 1989 C standard is (mostly) still a subset of C++, albeit C++ provides alternatives to a lot of the features that are in C.

    There are very few tasks that, objectively, C or C++ are suited where the other is poorly suited. There are trade-offs, but the trade-offs are not as marked as they were in the past. Human preference is what often sways the choice.

    Quote Originally Posted by s5s View Post
    I know C is a lot simpler that C++ and a simpler thing is easier to use even when you are a master on the subject.
    You know wrong.

    C is actually quite a complex language and library. It is true that C++ is more complex. However, C is not so simple that it is significantly easier to learn than C++. C is complex enough that it is difficult to learn. The relative ease of learning C or C++ depends on the mindset of the person learning it, rather than their complexity. For some people, the complexity of C is easier to grasp than the complexity of C++. And vice versa. And some people are able to learn both, and use either one, depending on the task at hand.

    The "C is simpler than C++" mantra was originally part of the political mantra of some C developers trying to slow down the rate at which some of their colleagues took up C++.

    Quote Originally Posted by s5s View Post
    3. What is the problem writing OOP code with C? You can code a single class in a single file.
    There are a lot of OO design features that C++ is designed to support, and C is not. It is possible to implement any OO design in C, but the amount of code that the programmer need to write to implement that design is usually larger. C++, on the other hand, was designed with OOP in mind, so the C++ compiler takes care of a lot of relevant details that a C programmer would need to account for.

    Quote Originally Posted by s5s View Post
    4. A lot of people talk about C and C++ as though they are totally different languages.
    They are, although the picture is murky as they have a large subset of syntax and library features in common.

    All programming languages are associated with particular design techniques, architectural approaches (how a system is conceptually organised), and idioms that programmers leverage to maximise their effectiveness in that language. C and C++ each have their own set of idioms, techniques, and architectural styles that they support better than each other. Irrespective of the fact that a lot of things can be done in the language/library subset that is common to both C and C++, the state of the art in both languages involves using VERY different techniques.
    Quote Originally Posted by s5s View Post
    I've heard expression such as "Oh you can't use C++ for that, you need to learn C.".
    Someone who says that doesn't actually understand either language properly.

    It is true that some designs are easier to implement in C or C++, but there is very little that one can do that the other absolutely cannot. The determinate is mindset and effort by the developer.

    Quote Originally Posted by s5s View Post
    Sure the libraries are different and there are some new keywords in C++ that do things that a library does in C but they are v. v. similar to me.
    You're focusing on syntax and libraries. The main areas where C and C++ differ are in architecture (how the program, overall, is structured) and contributing design techniques.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The argument that a C++ compiler is much more difficult to make, I think, is overrated.
    Remember: there exists today open source free C++ compilers that anyone can use.
    Of course, if you are using it for a new platform, then you need to rewrite parts of the compiler to produce proper assembly code. However, compilers typically tend to be split into front ends and back ends. The front ends compile into some immediate language that the back ends understands. The back ends then take that and make it into assembly code.
    The thing here is that the back end need to be rewritten for any given target platform, but the front end generally does not. Because of that, it generally doesn't matter if you are using C or C++, because either way, the back end needs to be rewritten and the front end is already written.
    The other problem is the standard library, and there are already good implementations since most of it is already written in standard C++, and the few parts that can usually be implemented by the front end.

    Yes, it will probably cost more than a C compiler, but not prohibitively more so.
    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. #22
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I think when people say that making a C++ compiler is hard they are talking about supporting standard features. Of course it is possible to start with a FOSS base, but what sets compilers apart usually is how completely they support the standard. And who knows how flexible a code base that you borrowed really is. It might not be very conducive to what you want your compiler to support on a specific platform.

  8. #23
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    1. I don't think either C or C++ are gaining in popularity these days. They are stable languages in widespread use, but they aren't gaining territory, mainly because there isn't too much territory to be gained.

    2. C doesn't really have a niche separate from C++. They both really target the same niche, but C++ aims to make object-oriented programming much simpler.

    3. OOP is certainly possible in C, but manually implementing common OOP features like polymorphism, multiple interfaces/inheritance, etc. using C isn't trivial, and you lose some compile-time type checking that you'd have in C++.

    4. They are very similar languages, but they are not the same. Think of them like Norwegian and Swedish - they are mutually intelligible to a large degree, but each has its differences. A lot of the differences are preferred style - while you could compile a well-written C program as C++ and mostly it will work, it's probably not going to look all that much like a well-written C++ program, because each language has its preferred method of doing things, especially in terms of input and string handling. Java and C# are also very similar languages to C and C++, though again each has its own flavor.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. confused with cin.get()
    By Shal in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2006, 07:27 AM
  2. confused
    By mopar123 in forum C Programming
    Replies: 18
    Last Post: 09-01-2005, 04:06 PM
  3. Confused
    By Clyde in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2004, 02:57 PM
  4. confused
    By luckyboy23 in forum C++ Programming
    Replies: 10
    Last Post: 04-30-2003, 06:09 AM
  5. I am so confused
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-27-2002, 10:17 PM

Tags for this Thread