免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
1234下一页
最近访问板块 发新帖
查看: 5833 | 回复: 35
打印 上一主题 下一主题

[其他] 我也想立传 [复制链接]

论坛徽章:
11
未羊
日期:2013-12-16 12:45:4615-16赛季CBA联赛之青岛
日期:2016-04-11 19:17:4715-16赛季CBA联赛之广夏
日期:2016-04-06 16:34:012015亚冠之卡尔希纳萨夫
日期:2015-11-10 10:04:522015亚冠之大阪钢巴
日期:2015-07-30 18:29:402015亚冠之城南
日期:2015-06-15 17:56:392015亚冠之卡尔希纳萨夫
日期:2015-05-15 15:19:272015亚冠之山东鲁能
日期:2015-05-14 12:38:13金牛座
日期:2014-12-04 15:34:06子鼠
日期:2014-10-16 13:40:4715-16赛季CBA联赛之八一
日期:2016-07-22 09:41:40
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-01-25 18:19 |只看该作者 |倒序浏览
鲁迅有云, “于是人以文传, 文以人传” 。。。。。。。。。。, 想想倒也是扬名立万的事情。
可是不会写。。。。。。咋办。。。。。。。。。。。。。。。。。。。

论坛徽章:
3
15-16赛季CBA联赛之山东
日期:2016-10-30 08:47:3015-16赛季CBA联赛之佛山
日期:2016-12-17 00:06:31CU十四周年纪念徽章
日期:2017-12-03 01:04:02
2 [报告]
发表于 2013-01-25 18:27 |只看该作者

很显然,LZ你文笔太差。别说写小说了。LZ的技术文章也是烂的一坨(嗯,。。。),我保证没人读。
哈哈。写技术文章也要求文笔的,不骗你啊。譬如上次你写的那个关于mmap的。上下文全无,什么读啊写啊,私有啊共享啊,全不指明操作对象。于是我鉴定为烂文。。。

为了告诉LZ怎么写技术文章,我决定把我写的一篇[还没写完,用来教我的学生的]就上传在这里,占下LZ的楼。。。

论坛徽章:
3
15-16赛季CBA联赛之山东
日期:2016-10-30 08:47:3015-16赛季CBA联赛之佛山
日期:2016-12-17 00:06:31CU十四周年纪念徽章
日期:2017-12-03 01:04:02
3 [报告]
发表于 2013-01-25 18:28 |只看该作者
=========================================================
1. about programming language

we use natural language to communicate each other. we express
our thoughts by natural language, like English, Chinese,
French, Japanese, etc.
programming language is different from natural language. for briefness,
we use programming language to communicate with computer.

computer can only understand binary, or machine code.
so obviously we can not use natural language to communicate with computer.
anyway, we should express our intention to computer. machine code is not
a good choice, because it's not human readable.

the intension issued to computer should be unambiguous. and we must give
a good form to express our intension, the form should be human readable.

so the first thing is, to specify the form, or to formulate a form -- or,
to specify the syntax of the language.
and the second thing is, to specify the semantics of the specified form.
when the form and the semantics of specified form is stipulated, we say,
we designed a language, the language is a formal language,
it's different from natural language, because the form is specified,
the semantics on specified form is specified, and they must be unambiguous.

but actually, computer don't understand the formal language too,
so we need a translator to translate the formal language to machine code
or computer instructions.
so a set of tools should be developed, to translate the formal language
to machine readable language.

we say, the specification of those form and semantics and how they be mapped
is the language standard, like C89, C99 is the standard of C.

we say, the set of tools which play a role of translator is the language
implementation, like gcc.

论坛徽章:
3
15-16赛季CBA联赛之山东
日期:2016-10-30 08:47:3015-16赛季CBA联赛之佛山
日期:2016-12-17 00:06:31CU十四周年纪念徽章
日期:2017-12-03 01:04:02
4 [报告]
发表于 2013-01-25 18:29 |只看该作者
=========================================================

2. tool chain and runtime environment

we don't need to design and implement a computer language ourself, it's
a hard work. and fortunately, there're good lanuages designed very well we can use.
C is a good choice.

so we learn C language, learn the syntax, learn the semantics related to the
specified syntax, and then use it to express our intension to computer.
for programming as a expert, many things should be known:

1). the way how the "translator" work -- in fact we don't need to care excessively,
except you want design and implement a lanaguage for yourself, or you want
to maintain those tools, or you just like it. to design and implement
a programming language is often an area of expertise, known as compilation principle,
you can study it if you like.
the translator is not just a tool. it's a set of tools. maybe the compiler is the
most important tool, it's the "real" translator; but it doesn't work if we just have
a compiler. GCC stands for "GNU Compiler Collections", it's a wrapper of many
compilers, C/C++, Fotran, Objective C, and so on.

2). the environment the program run on. we say the environment of the program running on
is runtime environment.

we've known that, the process to translate C to a executable program has four steps, each
step correspond a tool.
1) Preprocessor. the cpp.
2) Compiler. the cc1.
3) Assembler. the as(gas, GNU as).
4) Linker. the ld.

they collectively called tool chain.

论坛徽章:
3
15-16赛季CBA联赛之山东
日期:2016-10-30 08:47:3015-16赛季CBA联赛之佛山
日期:2016-12-17 00:06:31CU十四周年纪念徽章
日期:2017-12-03 01:04:02
5 [报告]
发表于 2013-01-25 18:31 |只看该作者
=====================================================

4. the translation steps

pretend there's a program composed of obj.c and main.c.
the example is in the attachment, lies in the dir compile.

we can invoke gcc on commandline like the following:
#gcc main.c obj.c

then an executable program named a.out will be yield.
gcc hide the process how it be made.
in fact, the 2 source files are preprocessed, compiled, and assembled independently, each source
file yield an object file, then the 2 object files is linked.

obj.c
\
\ preprocesser. substitute the macro string, and do header files include, etc.
\ #cpp obj.c > obj.i
\ or
\ #gcc -E obj.c -o obj.i
\
\------> obj.i
         \
         \ compiler, to compile C source file to assembly source file.
         \ the compiler is cc1. the compiler is wrapped by gcc,
         \ we can manually invoke it on commandline:
         \ (this command depend on platform, 4.4.3 is the gcc version on my system)
         \ #/usr/lib/gcc/x86_64-linux-gnu/4.4.3/cc1 obj.c -o obj.s
         \ or
         \ #gcc -S obj.c -o obj.s
         \
         \------> obj.s
                  \
                  \ assembler, to assemble the assembly source file to binary object file.
                  \ #as obj.s -o obj.o
                  \ or
                  \ #gcc -c obj.s -o obj.o
                  \
                  \------> obj.o

main.c
\
\ #gcc -c main.c -o main.o
\
\------> main.o

-------------------------------------------------------------------------------------
then, we link these 2 object files:
#gcc main.o obj.o

the program named a.out is yield.
in fact we can manually invoke ld on commandline to complete the link step.
but many details, at this occasion, are very complex. these details should be cared by gcc
but not us.
why? because in fact the C library should be linked with our object files -- we used printf in
our program. and printf is a routine lies in the standard C library. we know, libraries on
our system lies in dir /lib or /usr/lib, so the standard C library is /usr/lib/libc.a(static library)
or /lib/libc.so.*(shared object, or dynamic linked library). in most cases, if we just invoke
gcc like the above command, the .so library is linked; and some cases the static .a library is
used, so, the standard C library just supplied itself by .a and .so form.
and, the crt1.o, crti.o, crtn.o should be linked with our object files too. -- now just never mind
what these crt*.o are...
not over yet.

in fact, you can see the details what's gcc do at the link step. just add a --verbose or -v option:
#gcc main.o obj.o --verbose

see it?
so, if you really want to invoke ld manually, you can use the following command[it work on my platform,
ubuntu 10.04 LTS, x86_64. your environment is the about the same with me, so you can try it]:
#ld main.o obj.o /usr/lib/crt*.o -lc --dynamic-linker /lib/ld-linux-x86-64.so.2 -o main

the above ld invocation will yield the executable program main.
1) main.o obj.o /usr/lib/crt*.o should be linked.
2) -lc: -l is a option means to link a library; c is the .so library libc.so.6, -lc means to link the
   standard C library.
3) --dynamic-linker option specify the dynamic linker we need: /lib/ld-linux-x86-64.so.2

more complete command:
#ld main.o obj.o -dynamic-linker /lib/ld-linux-x86-64.so.2 /usr/lib/crt1.o /usr/lib/crti.o
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3
-lgcc  -lgcc_eh  -lc /usr/lib/gcc/i686-linux-gnu/4.4.5/crtend.o /usr/lib/crtn.o -o main

1) -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3 specify the dir in addition to the default path
   in which the ld search libraries.
2) you can ls these dirs in the above command.

tips: the above commands may be changed depend on different platform & system.
by the way, the ld's true colors is the program collect2.

so now you see why invoke ld manually on commandline is not a good idea.
-------------------------------------------------------------------------------------

a question:
why does compiler just translate C source language to assembly language?
why doesn't compiler translate C source language to object file directly?
a good question, isn't it?
let's shelve this question temporarily.

论坛徽章:
3
15-16赛季CBA联赛之山东
日期:2016-10-30 08:47:3015-16赛季CBA联赛之佛山
日期:2016-12-17 00:06:31CU十四周年纪念徽章
日期:2017-12-03 01:04:02
6 [报告]
发表于 2013-01-25 18:34 |只看该作者
剩下还有一大半, 不发了。

发这个的目的是要很明确滴告诉LZ,我用渣英文写的东西都比你写的那篇关于mmap的文章还容易明白,所以,写文章什么的,你必须向我学习{:3_189:}






哈哈,玩笑。立传什么的,我也想的{:3_189:}

论坛徽章:
4
戌狗
日期:2013-08-15 18:22:43技术图书徽章
日期:2013-08-21 13:48:45巨蟹座
日期:2013-09-26 17:06:39处女座
日期:2013-12-25 11:26:10
7 [报告]
发表于 2013-01-25 18:42 |只看该作者
要不我让你看看我在红河谷上发的嫖文? 绝对比这个坛子上大多数人文笔都好得多。基本做到了金圣叹的“每到极淫邪处,常以佛经比之”。

论坛徽章:
3
15-16赛季CBA联赛之山东
日期:2016-10-30 08:47:3015-16赛季CBA联赛之佛山
日期:2016-12-17 00:06:31CU十四周年纪念徽章
日期:2017-12-03 01:04:02
8 [报告]
发表于 2013-01-25 18:48 |只看该作者
回复 7# 塑料袋


    垃圾袋,嫖文我没兴趣,妞能免费送一晚给我不?

论坛徽章:
11
未羊
日期:2013-12-16 12:45:4615-16赛季CBA联赛之青岛
日期:2016-04-11 19:17:4715-16赛季CBA联赛之广夏
日期:2016-04-06 16:34:012015亚冠之卡尔希纳萨夫
日期:2015-11-10 10:04:522015亚冠之大阪钢巴
日期:2015-07-30 18:29:402015亚冠之城南
日期:2015-06-15 17:56:392015亚冠之卡尔希纳萨夫
日期:2015-05-15 15:19:272015亚冠之山东鲁能
日期:2015-05-14 12:38:13金牛座
日期:2014-12-04 15:34:06子鼠
日期:2014-10-16 13:40:4715-16赛季CBA联赛之八一
日期:2016-07-22 09:41:40
9 [报告]
发表于 2013-01-25 18:48 |只看该作者
本帖最后由 zylthinking 于 2013-01-25 18:50 编辑
塑料袋 发表于 2013-01-25 18:42
要不我让你看看我在红河谷上发的嫖文? 绝对比这个坛子上大多数人文笔都好得多。基本做到了金圣叹的“每到极 ...


你要装君子知道不 , 比如感叹一下中国人之浅薄浮躁, 忧心一下后代没有程序编之类的, 不就高大了吗, 非要把鸡鸡露出来, 自以为坦白, 其实流氓, 流氓干架是干不过人的

论坛徽章:
4
戌狗
日期:2013-08-15 18:22:43技术图书徽章
日期:2013-08-21 13:48:45巨蟹座
日期:2013-09-26 17:06:39处女座
日期:2013-12-25 11:26:10
10 [报告]
发表于 2013-01-25 18:55 |只看该作者
回复 9# zylthinking

我也想装君子装深沉,奈何心中无码,所见皆是A片。

就算佛经看完了,能回忆起来的也都是其中很黄很暴力的部分,没办法啊,不自觉的为之。。

   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP