ภาษาซีและ Arduino +โครงสร้างชุดทดลองการควบคุมตำแหน่งแบบ PID · (C Language) (Dennis Ritchie)
1 C/C++ Compiling. 2 A Brief History of C language In the early 1970s, Dennis Ritchie of Bell...
-
Upload
george-sullivan -
Category
Documents
-
view
218 -
download
0
Transcript of 1 C/C++ Compiling. 2 A Brief History of C language In the early 1970s, Dennis Ritchie of Bell...
1
C/C++ C/C++ CompilingCompiling
2
A Brief History of C A Brief History of C languagelanguage
• In the early 1970s, Dennis Ritchie of Bell Laboratories was engaged in a project to develop new operating system.
• He realized that he needed the use of a programming language that was concise and that produced compact and speedy programs.
• This need led Ritchie to develop the programming language called C.
3
A Brief History of C++A Brief History of C++• In the early 1980's, also at Bell Laboratories,
another programming language was created which was based upon the C language.
• This new language was developed by Bjarne Stroustrup and was called C++. According to Stroustrup, the purpose of C++ is to make writing good programs easier and more pleasant for the individual programmer.
• When he designed C++, he added OOP (Object Oriented Programming) features to C without significantly changing the C component. Thus C++ is a "relative" of C, meaning that any valid C program is also a valid C++ program.
4
Simple C programSimple C program // Add two numbers and print the result
#include <iostream.h>using namespace std;
void main(){
int firstNum, secondNum, result;cout<< “Please Enter the first Number”<<endl;cin>> firstNum;cout<< “Please Enter the second Number”<<endl;cin>> secondNum;result= firstNum + secondNum;cout<<firstNum<<“ + “<<secondNum<<“ = “<<result<<endl;
}
5
C/C++ source files suffixesC/C++ source files suffixes
• .cpp, .cc, .c suffixes are used for C++ programs that are to be preprocessed, compiled and assembled
• .c for C programs that are to be processed, compiled and assembled
• .h or preprocessor (header) files
6
File StructureFile Structure• Implementation files (.cpp, .cc, .c)
– Methods are implemented
• Interface files (.h)– Methods and classes are defined– Also called header files
• Implementation files depend on Interface files.– Interface holds prototypes and definitions– Implementation holds actual code
7
Compilation DetailsCompilation Details
object.h
object.cpp
main.cpp
object.s
main.s
object.o
main.o
Output
Source code Assembly Machine Code
8
Using GNU C CompilerUsing GNU C Compiler• GNU C compiler is one of the compilers installed
on willow server (UM research server)• GCC is the official compiler of the GNU• gcc file1.c command is used to compile and link a C
program on willow with the gcc compiler• g++ file1.c command is used to compile and link a
C++ program on willow with the gcc compiler
• gcc prog.c command creates an executable file known as a.out
9
More on gcc commandMore on gcc commandgcc filename [flag]
-c
Compile or assemble the source files, but do not link.
-S
Stop after the stage of compilation proper; do not assemble.
-E
Stop after the preprocessing stage; do not run the compiler proper.
-o newFilename
Place output in file newFilename instead of a.out