Lab 1: Getting to know the compiler

Hints and Tips


WARNING: All definitions are ONLY relative to Visual Studio! It can work elsewhere but not all can.

Definitions:

Compiler: A program that converts your high level language (C++) into a running program... and many other tasks that you don't need to know about.

Compile: The process of converting a high level language (C++) into assembly with relative memory reference
           WHAT IT MEANS: It's the process that checks for syntax errors in your code.

Link: Turning relative memory references in the assembly to absolute references. It is also implied that the program will be turned into an executable (a running program) at that time.
           WHAT IT MEANS: It turns your compiled code into a running program.

Build: The process of both compiling and linking. This is done so that you can have a program ready to run with one command. This can also be done with multiple projects (not necessary for you to know).

Syntax Errors: An error that is caused by bad grammar or typos and such in a code. (i.e. you forgot a semicolon at the end of a statement)

Link Error: This usually means that you told C++ that you have something when it really doesn't exist. A good example is if you created the wrong type of project and the compiler is trying to look for a WinMain function instead of a main function.

Runtime Error: Anything bad that happens when you run your program after the build. Common examples are really odd looking outputs, a possessed program (keep doing stuff when you don't know what's going on), bad calculation, crashes, and the blue screen of death. These are sometimes called Semantic Errors, semantic means meaning. The common cause of these are bad calculations, misusage of pointers, and bad conditions that makes no sense. Another common problem is running out of resource or lack of permission on a public computer.

Debug: The process of making a bad code work. This can be fixing syntax or semantic errors.


Common Errors:

(coming soon)


Shortcuts and Tricks:

Function A does not take X number of parameters.

  1. You gave a function too many arguments. For example: pow(a,b,c)... which doesn't work because it's the power function. Another good example is cout << "hi" , "you"; That will not work because of the comma. C++ will treat that comma as some sort of argument separater.
  2. You declared the function one way in the prototypes and then decided to add a parameter somewhere down the road. What I mean is you somehow decided to add a parameter to the function at one point and forgot to update the prototype to reflect that change down the road. When you decide to call that function and use the changed parameter list it doesn't match the prototype. This will also lead to other bigger problems like link errors down the road if this doesn't get resolved.

Creating a project in Visual Studio (or Visual C++):

Visual Studio is the name of a set of compilers created by the Microsoft Corporation. The one that we are using is Visual C++. Depending on the year of your copy you may have Visual C++ v.6, Visual Studio .NET, or Visual Studio .NET 2003, in chronological order. I will not include instructions for Visual C++ since it is quite obsolete in my opinion. If you do want to use it, however, contact me and I'll try to help.

There are many ways to start a project in Visual Studio (it's the same in both .NET and .NET 2003) but I will only describe one for simplicity.

  1. File->New->Project (Ctrl+Shift+N)
  2. Choose the "Visual C++" folder (selection box on your left) in the "Project Type" section
  3. Choose "Win32 Project" (selection box on your right) in the "Templates" Section
  4. Under the "Name" field, type in the name of your project (this will also be the name of the folder for the project)
  5. Under the "Location" field, chose the location that your project should be in (this should be somewhere that you have regular access to)
  6. Press OK

This is the box that should pop up after step 1:

The bad circling job with the numbers next to it refers to the steps that they illustrate.

  1. Choose the "Application Settings" tab on the left
  2. In the "Application Type" group choose "Console Application"
  3. In the "Additional options" group choose "Empty Project"
  4. Press OK

This is what you should see after step 6:

Once again the really bad circling job with the numbers next to it illustrates the steps they indicate.

  1. Now you have a blank project with nothing so you need... a file. File->New->File (Ctrl+N)
  2. In the "Categories" section select "Visual C++"
  3. In the "Templates" section select "C++ File (.cpp)"
  4. Press Open

This is what you should see after step 11

Once again the really bad circling job with the numbers next to it represents the step it illustrates.

  1. Now save this file, File->Save (Ctrl+S)
  2. Name it anything you'd like but I personally prefer to name it main (because mostlikely it's your main file)