What is the difference between C++ and a compiler

In summary, the language c++ is defined by a standards committee, and a compiler is only necessary to run the code. However, you will need an "environment" to really use the language, and this environment is typically provided by the compiler.
  • #1
Lucid Dreamer
25
0
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?
 
Technology news on Phys.org
  • #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.
 
  • #3
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.
 
  • #4
Thank you Dacruick and Phinds for the replies. It makes much more sense now!
 
  • #5
Lucid Dreamer said:
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?
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.
 

1. What is the difference between C++ and a compiler?

C++ is a programming language, whereas a compiler is a software tool used to convert human-readable code into machine-readable code. C++ is a high-level language that is used to write programs, while a compiler is used to translate these programs into instructions that a computer can understand and execute.

2. Is C++ a compiler or a programming language?

C++ is a programming language. It is a general-purpose language that is used to create a wide range of applications, from simple scripts to complex software.

3. Can you write C++ code without a compiler?

No, in order to run C++ code, you need to have a compiler. Without a compiler, the code cannot be translated into machine-readable format and therefore cannot be executed by the computer.

4. Is a compiler necessary for every programming language?

No, not all programming languages require a compiler. Some languages, such as Python and JavaScript, use interpreters instead of compilers to translate code into machine-readable format.

5. How does a compiler work in relation to C++?

A compiler takes the source code written in C++ and translates it into machine code, which is a series of instructions that the computer can understand and execute. This allows the C++ program to be run on a computer or other electronic device.

Similar threads

  • Programming and Computer Science
Replies
29
Views
2K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
2
Replies
59
Views
5K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
6
Views
991
  • Programming and Computer Science
Replies
6
Views
1K
Back
Top