c语言从哪里开始编译的?

jydjdongjie 2011-09-15 06:49:50
都知道C是从main()开始执行的,但是没有关心过从哪里开始编译。
...全文
312 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
jydjdongjie 2011-09-20
  • 打赏
  • 举报
回复
呵呵,第一次发帖就得到这么多热心人的帮忙!谢谢各位了!
看了大家的回答,我想起来了:以前看过一次反汇编,确实是从头开始编译的。
Athenacle_ 2011-09-16
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 micropentium6 的回复:]

Correct me if I am wrong

GCC compilation process:
1. Pre-processing through CPP: c source cods
resolve dependencies, text substitution (macro,include), output is a single file

2. GCC Par……
[/Quote]

这是编译的步骤:预编译→词法→语法→语义→中间代码(RTL)生成→代码优化→汇编→链接;

不过就LZ的意思,我说,编译是从预处理后的文件的第一个字母开始编译的
  • 打赏
  • 举报
回复
a good 101 reference could be found here:

http://www.tenouk.com/ModuleW.html
  • 打赏
  • 举报
回复
Correct me if I am wrong

GCC compilation process:
1. Pre-processing through CPP: c source cods
resolve dependencies, text substitution (macro,include), output is a single file

2. GCC Parse: output from CPP
Parse the source and create the tree structures in RTL (register transfer language) output is RTL

3. GCC Code Optimization: RTL tree
Optimize code through all kind of criteria: Constant Folding, Code Elimination... output is in assembly code

4. ar: assembly code
generate object files in binary format

5. ld: object files
relocate object code, add other object files/symbol table, link libraries. output is the executable file
AndyZhang 2011-09-16
  • 打赏
  • 举报
回复
反汇编一下,看汇编语言就知道从哪里开始了
赵4老师 2011-09-16
  • 打赏
  • 举报
回复
从.c或.cpp的第一个字符。
赵4老师 2011-09-16
  • 打赏
  • 举报
回复
《程序员的自我修养--链接、装载与库》
txzsp 2011-09-16
  • 打赏
  • 举报
回复
流程上是按照项目文件进行对每个文件逐个编译生成.obj文件的。
绿野耕夫 2011-09-16
  • 打赏
  • 举报
回复
《编译原理》或者《程序员的自我修养--链接、装载与库》
后一本书看起来有趣味些~~
如此的肤浅 2011-09-16
  • 打赏
  • 举报
回复
其实我也在想这个问题
shiter 2011-09-16
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zhao4zhong1 的回复:]
《程序员的自我修养--链接、装载与库》
[/Quote]
作者???
hondely 2011-09-16
  • 打赏
  • 举报
回复
路过 学习下
afreet2006 2011-09-15
  • 打赏
  • 举报
回复
不知道, 关注中
Athenacle_ 2011-09-15
  • 打赏
  • 举报
回复
从头开始编译的。。

其实从main开始执行是链接器的事,你也可以指定从其他的函数开始执行,对编译器来说,main是再普通不过的一个函数而已。。

不过我可以确定的告诉你,编译的话,是从头开始编译的,,,具体请看编译原理
AnYidan 2011-09-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zmlovelx 的回复:]
这个得看编译原理了.

预编译--编译--汇编--链接.
[/Quote]

编译原理
帅得不敢出门 2011-09-15
  • 打赏
  • 举报
回复
main之前还有许多工作的.
全局域的变量(包括静态变量)初始化等工作都是在main之前执行的
帅得不敢出门 2011-09-15
  • 打赏
  • 举报
回复
这个得看编译原理了.

预编译--编译--汇编--链接.

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧