What is the difference between C++ and a compiler

Click For Summary

Discussion Overview

The discussion centers around the differences between the C++ programming language and its compiler, exploring foundational concepts for beginners in programming. Participants express confusion about the necessity of a compiler for using C++ and the relationship between the language and its implementation.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant expresses confusion about the distinction between C++ as a language and its compiler, questioning if C++ can be used without a compiler and whether the language is contained within the compiler.
  • Another participant explains that the compiler interprets C++ code and is part of a broader development environment that aids in debugging and organizing code.
  • A different participant emphasizes the necessity of a development environment for practical programming, noting that debugging tools are essential for resolving errors that will inevitably occur.
  • Further elaboration is provided on the role of the standards committee in defining the C++ language, highlighting that compiler vendors may encounter challenges in adhering to these standards and may implement features differently.
  • Concerns are raised about the concept of undefined behavior in C++, with examples given of constructs that may lead to unpredictable results, suggesting that compliance with standards can vary among compiler vendors.

Areas of Agreement / Disagreement

Participants generally agree on the necessity of a compiler for executing C++ programs, but there is no consensus on the implications of compiler behavior and the challenges faced by vendors in adhering to language standards. Multiple competing views on the relationship between the language and its implementation remain present.

Contextual Notes

Limitations include the complexity of language standards, the variability in compiler implementations, and the nuances of undefined behavior that can affect programming outcomes.

Lucid Dreamer
Messages
25
Reaction score
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
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.
 
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.
 
Thank you Dacruick and Phinds for the replies. It makes much more sense now!
 
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.
 

Similar threads

  • · Replies 29 ·
Replies
29
Views
4K
Replies
6
Views
3K
  • · Replies 17 ·
Replies
17
Views
4K
Replies
59
Views
10K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 22 ·
Replies
22
Views
4K
Replies
14
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 27 ·
Replies
27
Views
6K
Replies
86
Views
3K