Differences between revisions 8 and 9
Revision 8 as of 2006-04-26 11:19:35
Size: 4515
Editor: jnan
Comment:
Revision 9 as of 2006-04-26 11:23:55
Size: 4629
Editor: jnan
Comment:
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:

= Coding Style =
  * 先看 [http://lxr.linux.no/source/Documentation/CodingStyle Linux kernel coding style]

TableOfContents

1. 关于我

个人信息

http://blog.woodpecker.org.cn/planet/images/someone.png

Jick Nan

邮件

[email protected]

主页

http://jick.nan.googlepages.com

Blog

[http://my.donews.com/jnan/ 梦南录]

2. Coding Style

3. C

3.1. malloc, calloc, free

  • 一个严重的错误:释放不是通过调用 malloc, calloc 得到的指针所指向的存储空间。
  • 使用已释放空间同样是错误的。

4. Gnu Tools

4.1. Vim

4.1.1. Edit a file

4.1.1.1. Move around quickly

  • If you set the incsearch option, Vim will show the first match for the pattern, while you are still typing it. This quickly shows a typo in the pattern.

  • If you set hlsearch option, Vim will highlight all matches for the pattern with a yellow background.

  • If you see a specific word and want to search for other occurrences of the same word, use the * command to grab the word from under the cursor and search for the next one, while # search for the previous one.

  • In structured text(C/C++)
    • % can jump to many different matching items. It is very useful to check if() and {} constructs are balanced properly.

    • Use [{ to jump back to the "{" at the start of the current code block, and ]} for '}'.

    • Use gd to jump from the use of variable to its local declaration.

  • 可视(visual)模式,用于选定文本块;可以在正常模式下输入“v”(小写)来按字符选定,输入“V”(大写)来按行选定,或输入“Ctrl-V”来按方块选定。

4.1.1.2. Don't type it twice

  • If you want to change one word into another in the whole file, you can use the :s(substitute) command.

  • If you want to change one word into another only a few locations, a quick method is to use the * command to find the next occurrence of the word and use cw to change the word. Then type n to find the next word and .(dot) to repeat the cw command.

  • CTRL-N can auto complete function and variable names. Vim looks up words in the file you are editing, and also in #include'd files.

  • Vim has a mechanism to record a macro. You type qa to start recording into register 'a'. Then you type your commands as usual and finally hit q again to stop recording. When you want to repeat the recorded commands you type @a.

4.1.1.3. Fix it when it's wrong

  • It's normal to make errors while typing, this can be corrected with abbreviations: :abbr Lunix Linux.

  • The same mechanism can be used to type a long word with just a few characters: :abbr pn pinguin.

  • To find errors in your text Vim has a clever hightlighting mechanism. This was actually meant to be used to do syntax hightlighting of programs, but it can catch and highlight errors as well.
  • A more complex example: English text.

4.1.2. Edit more files

4.1.2.1. A file seldom comes alone

  • Tag mechanism works for jumping between files.
  • Another powerful mechanism is to find all occurrences of a name in a group of files, using the :grep command. Vim makes a list of all matches, and jumps to the first one. The :cn command takes you to each next match.

  • Positions the cursor on the name of the function in your file and type [i: Vim will show a list of all matches for the function name in the included files.

  • In vim you can split the text erea in several parts to edit different files.
  • There are more uses of multiple window. The preview-tag mechanism is a very good example.

4.1.2.2. Let's work together

  • Select some structured text in a list and sort it: !sort.

4.1.2.3. Text is structured

  • One of the simpler things is to speed up the edit-compile-fix cycle. Vim has the :make command, which starts your compilations, catches the errors it produces and lets you jump to the error locations to fix the problems.

4.1.3. Sharpen the saw

4.1.3.1. Make it a habit

  • You need to learn new commands and turn them into a habit.

4.2. CVS

5. 反馈

欢迎大家对我说三道四哪

jick_nan (last edited 2009-12-25 07:12:35 by localhost)