CSAPP: Chapter1.1~Chapter1.2

本文深入讲解了C语言的基础知识,包括文件类型、预处理器的作用、编译过程中的四个阶段:预处理、编译、汇编和链接。通过一个Hello World的例子,详细介绍了从源代码到可执行文件的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In a sense, the goal of this book is to help you understand what happens and why when you run hello on your system.

//The hello.c file.
#include <stdio.h>

int main()
{
  printf("hello, world\n");
  return 0;
}

1.1 Information Is Bits+Context

1)File categories.

Files such as hello.c that consist exclusively of ASCII characters are known as text files. All other files are known as binaryfiles.

2)C Programming Language

C was closely tied with the Unix operation system.

C is a small and simple language.

C was designed for a practical purpose.(Implement the Unix operation system)

ANSI: American National Standards Institute.

ISO: International Standards Organization.

1.2 Programs Are Translated by Other Programs into Different Forms 

1)Different Forms

high-level C program which is also called source file to low-level machine-language instructions to executable object files.

2)Compilation system collection

preprocessor, compiler, assembler, and linker

3)Compilation system

Preprocessing phase. The preprocessors modifies the original C program according to directives that begin with the ‘#’ character. For example, the #include <stdio.h> command in line 1 of hello.c tells the preprocessor to read the contents of the system header file stdio.h and insert it directly into the program text.The result is another C program named hello.is.

Compilation phase. The compiler translates the text file hello.i into the text file hello.s, which contains an assembly-language program.Assembly language is useful because it provides a common output language for different compilers for different high-level languages(For example, C and Fortran).

Assembly phase.The assembler translates hello.s into machine-language instructions, packages them in a form known as a relocatable object program, and stores the result in the object file hello.o.

Linking phase.Merge printf.o with our hello.o into a new executable object file that is ready to be loaded into memory and executed by the system.

如图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值