2015年7月31日

[讀書會] Intro to C and C++。1。Compilation Pipeline

相當沒重點的噗浪連結請按我,上課用的講義按我

上課講義整理+心得:

為什麼要學C?
  • 要求Performance
    • zero-overhead principle,清爽零負擔
  • 要直接和硬體接軌
    • 硬體 → 組合語言 → C → C++ → C++11,後面的是用來整理前面的
Compilation pipeline
從Source code變成可以執行的程式之間,到底發生了什麼事?
  • pre-process:剪剪貼貼。包括以下幾種動作:
    • #include
      • 把其他檔案貼過來。
      • 不是import?
    • #define
      • 把某些字代換成其他字。也叫做 macro。可以減少打字時間。
    • #ifdef 或 ifndef
      • 如果有定義某個變數,就執行從 #ifdef (變數)...到 #endif 之間的code。可以定義一些debug用的訊息,正式release的時候不要設變數就不會印出來。
  • Compile:把 source code 轉換成CPU指令 assembly language。這時候得注意:
    • Type checking
      • C很邪惡,type不對只會給warning。基本上任何兩個type都可以互相cast,不過你不會想要這樣的吧寶貝
    • Linear Processing
      • 只有C這麼煩,要用的function一定要先寫或先定義。
  • Link:把不同的檔案合在一起?

其他雜七雜八
< > angle brackets:compiler會去系統資料夾裡找檔案
"" double quotes:在目前的資料夾裡找檔

作業小心得

  • 安裝cygwin的說明在這邊,安裝時請選擇gcc-core, gcc-g++, gdc等package。這些是C 的compiler。
  • 作業 2 題目 2 給的檔案有以下 code,在 #ifdef 之後 #define 用在如果已經有 include 過相同的function那就不要用這個,如果沒有就用這個。

#ifndef _FIBONACCI_H
#define _FIBONACCI_H
.....
#endif









[讀書會] Intro to C and C++。總整理

使用的是 MIT Open course 的 Introduction to C and C++,連結在這裡

總共有以下八個章節:

  1. Compilation Pipeline (連結,更新中)
  2. Control Structures, Variables, Scope, and Uninitialized Memory
  3. C Memory Management
  4. Data Structures, Debugging
  5. C++ Introduction, Classes, and Templates
  6. C++ Inheritance
  7. Parent Destructors, C++ Casts, References, Namespaces, Operator Overloading, Streams 
  8. Standard Template Library, Exceptions, Function Pointers, C++11