Jump to content

Cplusplus: Difference between revisions

83 bytes removed ,  6 March 2008
remove some of the crap
mNo edit summary
(remove some of the crap)
Line 1: Line 1:
'''Under construction, LOL.'''
'''Under construction.'''


''If you have any problems with this tutorial or want to give feedback, ask questions or get additional help, please e-mail coconut<at>redbrick<dot>dcu<dot>ie or, for general [[Helpdesk]] queries, helpdesk<at>redbrick<dot>dcu<dot>ie. Go go Power Rangers...''
''If you have any problems with this tutorial or want to give feedback, ask questions or get additional help, please e-mail coconut<at>redbrick<dot>dcu<dot>ie or, for general [[Helpdesk]] queries, helpdesk<at>redbrick<dot>dcu<dot>ie. ''


'''C++''' is an object-oriented programming language, developed as a superset of the language [[C]], which means that the language is essentially C with more features, hence the name. However, it has since evolved into a separate language and compatiblity with C is no longer guaranteed.
'''C++''' is an object-oriented programming language, developed as a superset of the language [[C]], which means that the language is essentially C with more features, hence the name. However, it has since evolved into a separate language and compatibility with C is no longer guaranteed.


It is a very popular all-purpose language which is commonly utilised for game programming, and in many respects is quite similar to [[Java]], another object-oriented language.
It is a very popular all-purpose language which is commonly utilised for game programming, and in many respects is quite similar to [[Java]], another object-oriented language.
Line 11: Line 11:
The page [[Programming On Redbrick]] explains how to compile programs written in C++. Here we will go  into more depth as to how the compiler g++ works.
The page [[Programming On Redbrick]] explains how to compile programs written in C++. Here we will go  into more depth as to how the compiler g++ works.


A compiler works by translating your programming language (in this case, C++) into assembly language, which is the basic language that a processor understands. While C++ is a universal language (source code written on one architecture will generally work on another unless special libraries are used), programs must be recompiled if they are to be used on different architectures - for example, if you are compiling on murphy, which uses the UltraSPARC architecture, you will have to recompile your program if you wish to use it on carbon or deathray, which use the Intel x86 architecture, because UltraSPARC and x86 assembly languages are completely different.
A compiler works by translating your programming language (in this case, C++) into opcode, which is the basic language that a processor understands. While C++ is a universal language (source code written on one architecture will generally work on another unless special libraries are used), programs must be recompiled if they are to be used on different architectures - for example, if you are compiling on murphy, which uses the UltraSPARC architecture, you will have to recompile your program if you wish to use it on carbon or deathray, which use the Intel x86 architecture, because UltraSPARC and x86 assembly languages are completely different.


g++ is the free, open-source C++ compiler which is included with many distributions of Linux as part of the gcc package, the latter of which is a C compiler. Other popular C++ compilers include Borland C++ and Microsoft Visual C++, however these are proprietary. gcc (and g++) is the most widely ported and universally available compiler in the world.
g++ is the free, open-source C++ compiler which is included with many distributions of Linux as part of the gcc package, the latter of which is a C compiler. Other popular C++ compilers include Borland C++ and Microsoft Visual C++, however these are proprietary. gcc (and g++) is the most widely ported and universally available compiler in the world.
Line 21: Line 21:
  mkdir C++
  mkdir C++


This will create a directory called "C++" in your home directory. Open up this directory by typing
This will create a directory called "C++" in your home directory. Enter this directory by typing


  cd C++
  cd C++


Now you're ready to create your first C++ program. For this tutorial, we are going to use the [[nano]] editor, as it is simpler than the alternative, vim. Make a new C++ source file, that we will call "first", with
Now you're ready to create your first C++ program. For this tutorial, we are going to use the [[nano]] editor. Make a new C++ source file, that we will call "first", with


  nano first.cpp
  nano first.cpp
56

edits