1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un



Similar documents
02

华恒家庭网关方案

CC213

FY.DOC

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

ebook8-30

C/C++ - 文件IO

C/C++语言 - C/C++数据

_汪_文前新ok[3.1].doc

C/C++语言 - 运算符、表达式和语句

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

C/C++ - 字符输入输出和字符确认

C/C++ - 函数

Microsoft Word - 11.doc

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

ebook50-15

Microsoft PowerPoint - ds-1.ppt [兼容模式]

Eclipse C C++, or

プログラムの設計と実現II

C/C++程序设计 - 字符串与格式化输入/输出

C/C++ - 字符串与字符串函数

Microsoft Word _Java_術科 .doc

Windows RTEMS 1 Danilliu MMI TCP/IP QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos eco

新版 明解C言語入門編

第 1 页共 9 页 文档履历 版本号日期制 / 修订人内容描述 V 正式版本

C++ 程式設計

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO

陕西职业技术学院(用标志)

51 C 51 isp 10 C PCB C C C C KEIL

C/C++ 语言 - 循环

Microsoft Word _2 課本1225_OK_0222修.doc

C

C C

一 总 体 要 求 一 ) 严 格 把 握 定 义 地 方 政 府 融 资 平 台 是 指 出 地 方 政 府 自 资 设 立 并 承 担 连 带 还 款 责 任 的 机 关 事 业 企.l 三 类 法 人 ( 二 ) 完 善 " 名 单 制 " 管 理 各 银 行 要 继 旗 完 善 融 资 平

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

EK-STM32F

Microsoft Word - 第3章.doc

Microsoft Word - MSP430 Launchpad 指导书.docx

投影片 1

CH01.indd


新・解きながら学ぶC言語

Microsoft Word - CPE考生使用手冊 docx

2102冬季

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

untitled

全国计算机技术与软件专业技术资格(水平)考试

nooog

新・明解C言語入門編『索引』

2.1 n ~á CPU q ˆ ~ µƒã î ˆ C++ à nù eô 1. (edit) 2. Í (preprocess) 3. (compile) 4. (link) 5. (load) 6. ˆ (execute) µl ô Ãs nù (editor) Í (preprocessor

C语言的应用.PDF

CC213

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

三 紀 錄 課 堂 上 可 見 的 學 習 情 況, 無 法 紀 錄 學 生 個 別 的 學 習 歷 程 四 教 師 無 彈 性 的 不 變 的 教 學 時 間 五 以 課 本 及 課 程 指 引 作 為 教 學 的 主 要 依 據 六 教 師 主 導 學 生 的 學 習 行 為 由 教 師 解 決

闖 關 組 4. 任 一 隊 員 曾 獲 得 第 一 屆 第 2 次 全 國 大 專 ITSA 盃 程 式 設 計 桂 冠 挑 戰 大 賽 菁 英 組 前 三 名 或 歷 屆 全 國 大 專 ITSA 盃 程 式 設 計 桂 冠 挑 戰 大 賽 挑 戰 組 前 三 名 應 報 此 組 5. 任 一

科学计算的语言-FORTRAN95

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

untitled

378高雄市都市計畫說明書

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

PowerPoint 演示文稿

untitled

简 介 本 白 皮 书 高 度 概 述 了 支 持 移 动 互 联 网 设 备 (Mobile Internet Device) 的 Intel C++ Software Development Tool Suite for Linux* OS, 目 标 读 者 主 要 是 技 术 决 策 制 订

epub83-1

D C 93 2

C 1



第3章、Linux下C编程基础

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%

Microsoft PowerPoint - plan06.ppt

从 因 人 设 事 谈 起 一 部 文 学 作 品 ( 尤 其 是 长 篇 小 说 ) 的 结 构 至 关 重 要, 因 为 它 是 文 本 整 体 的 组 织 方 式 和 内 部 构 造, 既 是 形 式 又 是 内 容 ; 乃 是 表 达 主 题 最 有 效 的 艺 术 手 段 元 代 戏 曲

循经指压疗法

Microsoft Word - HERBRECIPES《中國藥膳》.doc

毛主席的猪

表3:

, 即 使 是 在 昏 暗 的 灯 光 下, 她 仍 然 可 以 那 么 耀 眼 我 没 有 地 方 去, 你 会 带 着 我 么 杜 晗 像 是 在 嘲 笑 一 般, 嘴 角 的 一 抹 冷 笑 有 着 不 适 合 这 个 年 龄 的 冷 酷 和 无 情, 看 着 江 华 的 眼 神 毫 无 温

附件1.FIT)

Oracle Solaris Studio makefile C C++ Fortran IDE Solaris Linux C/C++/Fortran IDE "Project Properties" IDE makefile 1.

北魏山东佛教文化个案研究

苏州科技学院

新・解きながら学ぶJava


2 2 3 DLight CPU I/O DLight Oracle Solaris (DTrace) C/C++ Solaris DLight DTrace DLight DLight DLight C C++ Fortran CPU I/O DLight AM

高 职 计 算 机 类 优 秀 教 材 书 目 * 序 号 书 号 (ISBN) 书 名 作 者 定 价 出 版 / 印 刷 日 期 ** 配 套 资 源 页 码 计 算 机 基 础 课 计 算 机 应 用 基 础 刘 升 贵 年 8 月

摘 要 在 這 忙 碌 的 社 會 中, 普 遍 人 們 運 動 時 間 其 實 並 不 充 裕, 體 力 越 來 越 差 的 情 況 下 還 隨 意 飲 食 導 致 身 體 健 康 越 來 越 差, 因 此 本 專 題 打 算 利 用 健 康 飲 食 的 方 式 改 善 這 些 人 的 體 質,

附件3

untitled

C

提纲 1 2 OS Examples for 3

Microsoft PowerPoint - lect01.ppt

Chapter 9: Objects and Classes


附录J:Eclipse教程

职 位 类 别 : 测 试 工 程 师 工 作 经 验 或 实 习 经 历 : 不 限 岗 位 要 求 : 1. 本 科 及 其 以 上 学 历, 计 算 机 相 关 专 业 2014 届 毕 业 生 ; 2. 实 习 时 间 要 求, 尽 量 一 周 五 个 工 作 日 ; 3. 熟 悉 Wind

PIC_SERVER (11) SMTP ( ) ( ) PIC_SERVER (10) SMTP PIC_SERVER (event driven) PIC_SERVER SMTP 1. E-

Oracle Oracle Solaris Studio IDE makefile C C++ Fortran makefile IDE Solaris Linux C/C++/Fortran Oracle IDE "P

云 浮 市 总 工 会 学 习 贯 彻 市 委 五 届 九 次 全 会 精 神 全 省 工 会 第 二 季 度 暨 上 半 年 劳 资 纠 纷 研 判 会 召 开 河 源 市 总 工 会 召 开 劳 资 纠 纷 研 判 会 议 湛 江 市 总 工 会 召 开 上 半 年 劳 资 纠 纷 研 判 会

目次 

摘 要 就 一 个 游 戏 而 言, 对 于 参 与 者, 需 要 研 究 不 同 的 策 略 去 达 到 胜 利, 而 对 于 游 戏 设 计 者, 则 需 要 研 究 这 个 游 戏 的 平 衡 性 与 记 分 规 则 的 合 理 性, 并 不 断 去 调 整 它 们 在 本 文 中, 我 们

Transcription:

Linux C July 27, 2016 Contents 1 Linux IDE 1 2 GCC 3 2.1 hello.c hello.exe........................... 5 2.2............................... 9 2.2.1 -Wall................................ 9 2.2.2 -E.................................. 10 2.2.3 -D.................................. 11 2.2.4.............................. 13 1 Linux IDE IDE Integrated Development Environment, IDE Windows Visual Studio Java Eclipse IDE IDE IDE IDE IDE IDE = + + VS Eclipse IDE Emacs Emacs 1

1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Unix do one thing, and do it well Emacs do one thing, and do it well Emacs IDE VC C/C++ eclipse Java MS-Word Everything Emacs VC/eclipse/MS-Word Emacs 18 IDE Emacs Emacs Emacs Ctrl-h t, 2

2 GCC Ctrl-h i m emacs Emacs ; Ctrl-h i m emacs lisp intro Emacs Lisp Ctrl-h i m elisp elisp Google Happy emacsing! 2 GCC GNU Compiler Collection (GCC) GNU gcc: c g++: c++ gcj: java gfortran: Fortran GNAT: ada gccgo: Go GCC gcc GCC gcc c gcc GNU Richard Stallman gcc 1987 Unix-like Linux gcc gcc x86, ARM x86 ARM gcc man gcc wc -l gcc gcc gcc c c hello.c, 1 #include <stdio.h> 2 3 int main(void) 4 { 5 printf("hello, world!\n"); 6 return 0; 7 } 3

2 GCC gcc hello.c a.out a.out gcc hello.c -o hello hello -o output, hello./hello./ hello.c Hello, world! hello.c, 1 #include <stdio.h> 2 3 int main(void) 4 { 5 printf("hello, world!\n") 6 return 0; 7 } gcc hello.c, 1 hello.c: In function main : 2 hello.c:6:3: error: expected ; before return 3 return 0; 4 ^ OMG! 1. main 2. 6 3 r 3. ^ r, hello.c, return ) 1 #include <stdio.h> 2 3 int main(void) 4 { 5 printf("hello, world!\n"); 6 return 0; 7 } 1 hello.c: In function main : 2 hello.c:5:3: error: stray \357 in program 4

2.1 hello.c hello.exe 2 GCC 3 printf("hello, world!\n"); 4 ^ 5 hello.c:5:3: error: stray \274 in program 6 hello.c:5:3: error: stray \233 in program 7 hello.c:6:3: error: expected ; before return 8 return 0; 9 ^ OMG!!! 2.1 hello.c hello.exe gcc hello.c -o hello.exe,, hello.exe, 5

2.1 hello.c hello.exe 2 GCC Emacs nano, vim, Hello, world! Emacs C C (c preprocessor) # 6

2.1 hello.c hello.exe 2 GCC #include<stdio.h> include stdio.h 1 #include<stdio.h> stdio.h cpp cpp hello.c #include<stdio.h> 800 #define SQR(x) (x * x), SQR(x), (x * x). cpp C gcc (Compiler) cpp Google C CPU C 1. C C i++ movl addl movl $0, -4(%rbp) $1, -4(%rbp) -4(%rbp), %eax i++ C hello.c hello.s: gcc -S hello.c hello.s 1 ^^I.file "hello.c" 2 ^^I.section.rodata 3.LC0: 4 ^^I.string "Hello, world!" 5 ^^I.text 1 Debian GNU/Linux /usr/include/stdio.h 7

2.1 hello.c hello.exe 2 GCC 6 ^^I.globl main 7 ^^I.type main, @function 8 main: 9.LFB0: 10 ^^I.cfi_startproc 11 ^^Ipushq %rbp 12 ^^I.cfi_def_cfa_offset 16 13 ^^I.cfi_offset 6, -16 14 ^^Imovq %rsp, %rbp 15 ^^I.cfi_def_cfa_register 6 16 ^^Imovl $.LC0, %edi 17 ^^Icall puts 18 ^^Imovl $0, %eax 19 ^^Ipopq %rbp 20 ^^I.cfi_def_cfa 7, 8 21 ^^Iret 22 ^^I.cfi_endproc 23.LFE0: 24 ^^I.size main,.-main 25 ^^I.ident "GCC: (Debian 5.4.0-6) 5.4.0 20160609" 26 ^^I.section.note.GNU-stack,"",@progbits hello.c C 2. x86 ARM, PowerPC, M68000,... CPU (Assembler) object file.o GNU Assembler (gas).o gcc -c hello.c gcc gas hello.o cat hello.o CPU hd hello.o 8

2.2 2 GCC (Linker).o ld hello.c,.o.o hello.c.o printf().o.o printf() hello.o printf().o 2 (Debugger) bug gdb Hello, world! bug hello.c hello.exe 2.2 gcc C -o, 2.2.1 -Wall W warning, all all -Warning wall.c 1 #include <stdio.h> 2 3 int main (void) 4 { 2 libc.so so shared object Unix Google shared object 9

2.2 2 GCC 5 printf ("Two plus two is %f\n", 4); 6 return 0; 7 } -Wall gcc wall.c, a.out Two plus two is 0.000000 -Wall gcc -Wall wall.c, wall.c: In function main : wall.c:5:11: warning: format %f expects argument of type double, but argument 2 has type int [-Wformat=] printf ("Two plus two is %f\n", 4); ^ %f -Wall, W 2.2.2 -E -E gcc, cpp gcc -E hello.c cpp hello.c cpp c preprocessor, Macro C Linux 1 #define INIT_LIST_HEAD(ptr) do { \ 2 ^^I (ptr)->next = (ptr);(ptr)->prev= (ptr); \ 3 ^^I} while(0) do-while INIT_LIST_HEAD(prt) do {} while(0) bug -E bug macro.c SQR(x) 1 #include <stdio.h> 2 #define SQR(x) (x * x) 3 int main() 4 { 5 int counter; /* counter for loop */ 6 for (counter = 0; counter < 5; ++counter) 7 { 8 ^^Iprintf("x %d, x squared %d\n", 9 ^^I counter+1, SQR(counter+1)); 10

2.2 2 GCC 10 } 11 return (0); 12 } SQR(x) x gcc -Wall macro.c, a.out, x 1, x squared 1 x 2, x squared 3 x 3, x squared 5 x 4, x squared 7 x 5, x squared 9 SQR(x) -E 1 /* 前 省 略 数 */ 2 int main() 3 { 4 int counter; 5 for (counter = 0; counter < 5; ++counter) 6 { 7 ^^Iprintf("x %d, x squared %d\n", 8 ^^I counter+1, (counter+1 * counter+1)); 9 } 10 return (0); 11 } 8 SQR(counter+1) (counter+1 * counter+1), ((counter+1) * (counter+1)), 1 #define SQR(x) (x * x) 1 #define SQR(x) ((x) * (x)) -E 2.2.3 -D Debug printf() bug printf() -D stackoverflow.c, 1 #include<stdio.h> 2 11

2.2 2 GCC 3 int i=0; 4 5 int main(void) 6 { 7 #ifdef DEBUG 8 printf("%d\t",i++); 9 #endif 10 main(); 11 return 0; 12 } 8 printf() i 7 9 gcc -Wall stackoverflow.c./a.out, Segmentation fault printf() gcc -Wall -DDEBUG stackoverflow.c./a.out, Segmentation fault =i= 523629 -DDEBUG printf() -D #ifdef DEBUG... #endif DEBUG Macro -DDEBUG #define DEBUG 1 #ifdef DEBUG DEBUG #endif -D, DEBUG #ifdef DEBUG false, printf() -DDEBUG, DEBUG #ifdef DEBUG true, printf() printf() -D 12

2.2 2 GCC 2.2.4 gcc -g gdb debug -l l link pthread_create() pthread_create() man pthread_create NAME pthread_create - create a new thread SYNOPSIS #include <pthread.h> int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); Compile and link with -pthread. 1. #include <pthread.h>; 2. (a) pthread_create() int; (b) 4 3. Compile and link with -pthread, pthread Linux C Emacs gcc gdb bug Happy hacking! 13