Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What is the difference between C++ and a compiler

  1. Nov 30, 2011 #1
    Hello,

    I would like to start programming in c++ and after doing a quick internet search, I'm not sure where to start. From what I've read, I know I need a compiler, but my confusion arises from the fact that I don't understand what the difference is between the language c++ and its compiler. Is it possible to use c++ without a compiler? Is the programming language contained in the compiler?
     
  2. jcsd
  3. Nov 30, 2011 #2
    The compiler will basically interpret your code. Often, the compiler will be a subset of what is called an "environment". This environment will not only compile your code, but give you organizational options and give you the ability to easily debug codes or find errors. Technically, the compiler is all you will really need to run a code.

    I'm going to give you a weak analogy, but I hope it helps anyway :smile:.
    Let's say C++ is a language just like English is. English has a set of words, defined by a dictionary, and C++ does as well. When we speak, it is you and I that interpret the language, but for computers it will be the compiler that does so. Computer languages have their own version of grammar which is generally called syntax. C++ will have a much more rigid form of syntax in comparison to English (which contains a lot of slang and geographical variance), but it is still the same thing. The compiler will understand the processes that you’ve coded, and if you’ve used something that it doesn’t understand, it will highlight it and tell you that something is wrong with it. Much like you might ask me what I mean about a certain part of this explanation. If I was using improper punctuation, and words that perhaps you didn’t understand, you would highlight them for me and ask me, hey dacruick, I don’t get this.

    I want to emphasize that the C++ compiler is very rigid, as it is not a human. It expects a semi colon at the end of every line, and if it doesn’t get it then its going to complain. Humans on the other hand are able to fill in blanks and think on their feet. I hope this helps.

    And as for a compiler, I used Bloodshed to compile for C++. I didn’t do too much work with it, so others on this forum might be able to direct you to a better compiler. Searching “Bloodshed C++” on google will give you all the hits you need.
     
  4. Nov 30, 2011 #3

    phinds

    User Avatar
    Gold Member
    2016 Award

    As Dacruick said, all you HAVE to have to write and execute a program using the C++ language is a C++ compiler that will translate your C++ statements into machine language that the machine can understand. BUT ... if you actually want to get anything done then unless you are infallible, you really DO need the "environment" that he mentioned and you will need to learn how to use the debug facilities that it provides. Without that, when something goes wrong (and something WILL go wrong) you will have a hard time figuring out what it is.
     
  5. Nov 30, 2011 #4
    Thank you Dacruick and Phinds for the replies. It makes much more sense now!
     
  6. Nov 30, 2011 #5

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    The language is defined by a standards committee and is specified in a standards document. Amongst other things, the standard specifies what an implementation such as a compiler must do. Compiler vendors try to develop compilers that follow these strictures. Note that qualifier try to. There are a bunch of things that get in the way.

    When people (the standards committee is made up of people) try to specify a new language they invariably make mistakes. It is almost always the compiler vendors who find these mistakes because they are the ones who are trying to implement what the standard says to do. The vendors report the problem to the standards committee, interpret the intent of the requirement the best they can, and move on. Eventually the standards committee will issue a new revision of the standard, but that can take a very, very long time.

    Another problem is that sometimes the standards has some features that are very hard to implement. C++ has a few of these. Some vendors just give up and decide that they are not going to implement those features. A somewhat related problem is that some compiler vendors (a certain software company based in Redmond Washington is notorious for this) think they know better than the standards committee. They will implement something that goes against the grain of the standard.

    One final problem is that the C language introduced this ultra-nifty concept of undefined behavior. There are various constructs in C that just don't make sense such as j=i=--i+i++; or int arr[5]; arr[42]=0;. Anything a compiler vendor does against such undefined behavior is OK; the compiler is still compliant with the standard. Even wiping out your hard drive. It's OK! Bad as it is in C, C++ takes the concept of undefined behavior to even greater heights.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: What is the difference between C++ and a compiler
  1. C++ compilers (Replies: 24)

Loading...