Chapter 1: Start C-Language How To Speaker: Lung-Sheng Chien
OutLine Course skeleton Introduction of programming language How to use Visual C++ MSDN library Linux machine
Schedule: July : http://www.oz.nthu.edu.tw/~d947207/ 六 1 2 3 chapter 1 4 Chapter 2 5 Chapter 3 6 7 8 9 10 11 12 Chapter 4 Chapter 5 Chapter 6 Chapter 7 vim 13 14 數 15 數 16 數 17 數 18 數 19 數 20 數 21 數 22 數 23 數 24 25 26 27 28 29 30 31 Chapter 8 Chapter 9 Chapter 10
Workstations we have IP OS cpu memory 140.114.34.1 R705 Fedora 7 64-bit 140.114.34.11 R705 Fedora 7 64-bit 140.114.34.12 R705 Fedora 7 64-bit 140.114.34.13 R705 Fedora 7 64-bit 140.114.34.201 R705 RedHat 9 32-bit 140.114.34.214 R705 RedHat 9 32-bit 140.114.34.216 R705 RedHat 9 32-bit Intel(R) Xeon(R) CPU X5365 @ 3.00GHz, 2 cpu Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz Intel(R) XEON(TM) CPU 2.20GHz, 2 cpu Intel(R) Pentium(R) 4 CPU 3.00GHz Intel(R) Pentium(R) 4 CPU 3.00GHz 64 GB 8 GB 8 GB 8 GB 4 GB 2 GB 2 GB
Platform and resource platform Linux Windows compiler gcc, g++ icpc (Intel C compiler) vc 6.0 (Microsoft Visual Studio) editor vi vc IDE interface C++ document? MSDN Library 2008 GUI support Qt Qt Makefile generator qmake qmake + vc
R705 ( ) floorplanning 32-64 - 理 115 114 113 117 118 119 122 121 120 IP 140.114.34.117 ~119 are experimental computers in this course
Software list in experimental computer software description Visual studio 6.0 MSDN library 2008 Write C/C++ source code, compile and link C++ document Qt library ssh secure shell GUI programming and Makefile generator login workstations, it use MD5-encryption for connection
What we must learn C- basic skill Data structure stack, queue, tree Expression/loop analysis Networking FSM (Finite state machine) Regular expression Matrix class C++ (under Qt) 2D image Multithread technique 3D graphic Parallel computing Out-of-core programming
Topics in C-language Structure, including stack, queue, tree I/O, including Terminal, File Operators, function C- basic skill Pointer, array Primitive data type Control flow TextBook: The C Programming Language, Kernighan
Delivery after this course MATLAB (interpreter), symbolic toolbox 2-Elevators system Out-of-core programming 2D image (image processing), GIS, GRASS 3D graphic (mesh generator), finite element Maze ( 老 ) Prime number Compiler issue, debugger Issue about economy
OutLine Course skeleton Introduction of programming language How to use Visual C++ MSDN Library Linux machine
Sorts of Programming Language High-level language (C, C++, Java, Fortran, Verilog, VHDL, COBOL, ), independent of Machine Low-level language, assembly, depends on machine s architecture. Machine code, can be executed in cpu.of course it depends on machine architecture.
Why not Assembly or Machine code? awkward ( ) and low readability Operation is atomic, we need more abstract-like programming style Performance is Human-tuning, timeconsuming
Hierarchical view of Language High-level Language (C, C++, Fortran) Language translator High-level Language decompiler Compiler Assembly f2c : fortran to C is a language translator deassembler Assembler Machine code
C++ compiler we will use Compiler Author Windows Linux gcc, g++ GNU yes, with Cygwin yes Intel C++ Intel yes yes Visual Studio Microsoft yes no
Phases of a Compiler Source code Lexical analyzer Syntax analyzer ( ) We will cover this technique FSM Semantic analyzer ( ) Intermediate code generator Code optimizer Code generator machine code
Role of Compiler Shorten cycle of development - find the bugs - help programmers to write efficient and economic codes (relate to what language you use) Optimization, speed, low-power, Code generation
Standard of C/C++ ANSI C is current C-language standard, proposed by ANSI (American National Standard Institute ) Microsoft visual C has additional keywords not in C-standard, however this is o.k. if we write C codes under standard rule.
OutLine Course skeleton Introduction of programming language How to use Visual C++ - write Hello World program MSDN library Linux machine
Why visual studio (microsoft) IDE (Integrated Development Environment) Code editor Project management Debugger : weapon for learning C-language
Visual Studio IDE Microsoft Visual Studio 6.0 Microsoft Visual C++ 6.0
Step 1: (new project) [File] [New]
Step 2: console ( ) 2. helloworld 1. Win32 console 3. 料
Step 3: ( ) 1. 2. 靈
FileView Click FileView, no files are in this project. In directory helloworld, only project related files exist.
Step 4: [project] [Add to Project] [New] new
C++ main.cpp 1. C++ 2. main,cpp
Source Files 錄 main.cpp 1. 滑 main.cpp 2.
Step 5: 2. 1. Key in Text window
Step 6: Compilation ( ) : translate source code to object code 1. [Build] [Compile main.cpp] 2.
Step 7: Build (Linking phase, ) : combine object code into a executable file 1. [Build] [Build helloworld.exe] 2. Link message
Step 8: Execution ( 行 helloworld.exe) 1. [Build] [Execute helloworld.exe] 2. 行
What we have done! 行 Object code by compilation main.cpp
Source code s interpretation comments A compiler regards characters between /* and */ as comments and ignores them. Include information about standard library Std: standard, io: Input/Output Function body main is a function with 2 arguments and return integer (int) main calls library function printf to print string constant Hello world into screen return 0 corresponds to return type int of main
Key sentences 數 數 (argument) 數 (prototype) 參數 (parameter) 數 0 數 printf 數 (definition)
Purpose of #include <stdio.h> When compiler read printf("hello World\n");, it would recognize it is a function with function name printf, then compiler would do type checking, say one must declare prototype of function printf first such that compiler can do type checking. Example: comment #include <stdio.h>, then compile again, error occurs
錄 C:\Program Files\Microsoft Visual Studio\VC98\Include stdio.h 1. stdio.h, 滑 2. stdio.h, 滑, Visual Studio
[Edit] [Find] printf Find Next 3. 2. printf 1. Find stdio.h
Find prototype of printf in file stdio.h Not printf, F3 This is prototype of function printf printf("hello World\n"); Hello World 串, type checking int printf(const char *,...); 串
Declare prototype of printf before using it File stdio.h is not included 1. Declare prototype of printf 2. Call function printf Keywords, ifdef, extern, cplusplus, are explained later
Error: use printf before declaring its prototype, why? Compiler does not see any prototype
Why function main has no prototype? main is an entry point of program, it is unique, say only one main can appear. main has the definition, which is enclosed by a pair of brace. Declare prototype of function main Definition of main
Mismatch between prototype and definition Prototype of main Definition of main Overloaded is a C++ keyword, we will interpret later
OutLine Course skeleton Introduction of programming language How to use Visual C++ MSDN library Linux machine
MSDN Library MicroSoft Developer Network Includes sample code, technical articles, and C/C++ standard description It is free, you can download it from microsoft s download center
MSDN Library Microsoft Developer Network MSDN Library 1. MSDN Library 2. MSDN Library
printf [1] 1. search 2. printf enter 4. 3.
printf [2] Example code, you can copy it and test it Prototype of printf
OutLine Course skeleton Introduction of programming language How to use Visual C++ MSDN library Linux machine - use ssh to login remote machine - commands in Linux machine - How to compile
ssh (MD5 ) SSH Secure Shell Secure Shell Client
立 連 [1] Quick Connet
立 連 [2] 1. IP 3. Connect 紐 2.
立 連 [3]
立 連 [4] 1. imsl linux 錄 imsl
Commands in common use command passwd pwd ls cd mkdir rm top cat /proc/cpuinfo cat /proc/meminfo uname -a man icc, icpc gcc, g++ which Description Change password Current working directory List all files and subdirectory in current directory Change directory Make a new directory Remove a file/directory Show process information Show cpu s information Show memory s information Show machine s information Look up manual of commands Intel C/C++ compiler GNU C/C++ compiler Show full path of commands
uname -a linux.am.nthu.edu.tw : domain name 2.4.20-8smp : RedHat9 I686: 32, x86_64: 64
cat /proc/cpuinfo 1. CPU Pentium 4 2. Actual running clock rate
cat /proc/meminfo 2GB 2GB
top 2GB 2GB
pwd and ls 1. 錄 2. 列 錄 3. 4. pwd
mkdir 1. 錄 course
cd 1. 錄 course 2. 錄 3. 錄 course 2. cd.. 離 錄, 錄
Compiler icpc, gcc
which 1. Full path of command icpc 2. Full path of gcc 3. icpc 錄 4. icpc 錄
sftp [1] 1. sftp sftp (secure ftp) window 2. 錄 course
sftp [2] 滑 錄 helloworld
sftp [3]
[1] 1. 錄 course 2. 錄 helloworld 3. main.cpp 行 a.out 4. 行 a.out
[2] 1. a.out 3. a.out 2. g++ 4. 行
passwd : 1., entrer 2., enter 3., enter