-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIntro to Prg languages
52 lines (36 loc) · 3.24 KB
/
Intro to Prg languages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Machines understand only machine code (in 0s and 1s).
So previously ppl used to write prgs in machine code. Later they invented assembly code which is a bit readable (mov al 095h).
Assembler will transalte assembly code into machine code
Assembly languages tend to be very fast, and assembly is still used today when speed is critical. However, the reason assembly language is
so fast is because assembly language is tailored to a particular CPU. Assembly programs written for one CPU will not run on another CPU.
To address these issues we developed high level languages. C, C++, Pascal, Java, Javascript, and Perl, are all high level languages.
High level languages allow the programmer to write programs without having to be as concerned about what kind of computer the program is
being run on.
Programs written in high level languages must be translated into a form that the CPU can understand before they can be executed.
There are two primary ways this is done: compiling and interpreting.
A compiler is a program that reads code and produces a stand-alone executable program that the CPU can understand directly.
Once your code has been turned into an executable, you do not need the compiler to run the program.
Highlevel language prg ----> compiler (Specific to chipset)------> executable code (specific to chipset)----> cpu -----> results.
Ex: c, c++
An interpreter is a program that directly executes your code without compiling it into machine code first.
Interpreters tend to be more flexible, but are less efficient when running programs because the interpreting process needs to be done
every time the program is run. This means the interpreter is needed every time the program is run.
Highlevel langhuage prg -----> interpreter ------> cpu -----> results.
Ex: scripting lang like perl and javascript.
C++:
To convert each file of source code into a machine language file called an object file. Object files are typically named name.o or
name.obj, where name is the same name as the .cpp file it was produced from. If your program had 5 .cpp files, the compiler would
generate 5 object files.
Most Linux and OSX come with c++ compiler called g++.
g++ -c file1.cpp file2.cpp
will create file1.o and file2.o
-c will tell compiler to "compile only"
For complex projects, some development environments use a makefile, which is a file that tells the compiler which files to compile.
Makefiles are an advanced topic, and entire books have been written about them. (Not discussed in these tutorials)
Linking is the process of taking all the object files generated by the compiler and combining them into a single executable program
that you can run. This is done by a program called the linker.
A build configuration (also called a build target) is a collection of project settings that determines how your IDE will build your
project. The build configuration typically includes things like what the executable will be named, what directory the executable will
be output in, what directories the IDE will look in for other code and header files, whether to keep or exclude debugging information,
and how highly to have the compiler optimize your program. Generally, you will want to leave the settings at their default values
unless you have a specific reason to change something.