Friday, July 11, 2008

Linux/Unix Terminal

Terminfo database
At first, we need a database which describes capabilities of terminals. There are two basic databases there: TermCap and Terminfo. The latter is more widely used currently. You can create a new description file and edit it in textual mode. Then you can use a tool called tic to compile original text into binary format which is used by other programs. The Terminfo is generally located under: /usr/share/terminfo.
Some useful information you may care about can be accessed here and here. From there, you also can download latest terminfo database which contains information about many kinds of terminals.
Single UNIX Specification contains a section defining terminfo source format which can be accessed here.

Text terminal
Control terminals in low-level:
ioctls: gives very low-level access.
termios: "The termios functions describe a general terminal interface that is provided to control asynchronous communications ports."(From manpage).

High-level wrapper libraries:
Low-level APIs(ioctls/termios) don't hide complexity of terminal programming. Your programs must depend on specific terminal type. Some wrapper libraries exist which provide portable interface to many terminal types.
(1) ncurses (http://invisible-island.net/ncurses/ncurses.html)
Allow programmer to write TUI in a terminal-independent manner. It also does optimization work to reduce latency when using remote shells. Written in C.
Moreover, another package called Curses Development Kit(CDK) provides more functionalities. Mainly, it provides a library of curses widgets which can be used and customized in your programs.
Here is a good tutorial about how to use Ncurses in C.
Though ncurses tests $TERMINFO first, otherwise it reads from $HOME/.terminfo before the standard location,
(2) shell curses(http://www.mtxia.com/css/Downloads/Scripts/Korn/Functions/shcurses/)
It enables shell programmers to do TUI programming easily. It worked originally in Korn shell. I am not sure whether it has been ported to other shells.
(3) S-Lang

GUI
Currently, GUI exists almost everywhere in the computer world. Pure text terminal is not used very often. X window system is the big player in linux/unix. As a result, programmers can provide a GUI to the customers instead of TUI.
Some interesting articles: State of Linux graphics, various Linux/Unix desktops, X window resource/link collection.

Pseudo terminal/Terminal emulator
With disappearance(maybe a few ones still are being used) of traditional serial port terminals, code of terminal control was rewritten to promote reuse. So currently terminal is just a term describing such devices/programs which can send requests to master and handle responses from master. No physical serial port is involved. Most of the time we use remote shells running on internet. In directory /dev/, there are corresponding device files for these pseudo terminals. Commonly used file names are pty*, pts*,ptty...

Some useful commands:
(*) tic - the terminfo entry-description compiler.
translates  a terminfo file from source format into compiled format.  The compiled format is necessary for use with the library routines in ncurses.
(*)captoinfo (alias for tic) - convert a termcap description into a terminfo description
   infotocap(alias for tic) -
(*) screen: The screen program allows you to run multiple virtual terminals, each with its own interactive shell, on a single physical terminal or terminal emulation window.
/******* Set/Rest terminal ******/
(*) tset : terminal initialization
(*) setterm: set terminal attributes.
    setterm  writes  to  standard  output  a character string that will invoke the specified terminal capabilities. Where possible terminfo is consulted to find the string to use. The attribute names used in this command are different from cap names in terminfo database!!!
(*) stty - prints or changes terminal characteristics, such as baud rate.(related to line settings)
/****** Query  ********/
(*) infocmp - compare or print out terminfo descriptions. It can be used to print all capabilities.
(*) tput : query terminfo database. Query a specific capability.
e.g. tput setaf     //get foreground color.
       tput cols      //get number of columns
       tput longname  //get longname description of current terminal.
(*)  toe - table of (terminfo) entries. With  no  options,  toe  lists  all available terminal types by primary name with descriptions.

How to know your current terminal type?
tset -q
infocmp
How to tell linux type of your terminal?
Usually, you must explicitly tell linux type of your terminal. You can set environment variable $TERM.

Thursday, July 10, 2008

Unicode

Frequently, I am using utf-8, gb2312, ansii... For ANSII encoding, I understand it well becaues it is simple. For Unicode, I have been confused with various terms(e.g. utf-8, utf-16, utf-32, UCS-2, UCS-4...). Now, I do some research and summarize what I have learnt.

Resources:
Official site: http://www.unicode.org/
Unicode Standard (version 5): http://www.unicode.org/versions/Unicode5.0.0/bookmarks.html
Unicode FAQ: http://unicode.org/faq/
FAQ of various encoding forms: http://unicode.org/faq/utf_bom.html
Online tools:
An online Unicode conversion tool: http://rishida.net/scripts/uniview/conversion.php (Display various encoding representations of what you input.)
Unihan charset database: http://www.unicode.org/charts/unihan.html (You can query by Unicode code point.)
Another good tool: http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=%26%2320320%3B&mode=char

Windows XP provides a useful tool called "Character Map": Start -> All Programs -> Accessories -> System Tools -> Character Map.
In linux/Unix, iconv is a powerful tool which can be used to convert between different character encodings. (It seems BOM described below is not handled by iconv. So you should not include BOM in the source file.)

Two entities:
Unicode consortium
ISO/IEC JTC1/SC2/WG2
Good news is that these two entities are well synchronized and a standard from one entity is aligned to corresponding standard from the other entity.
Unicode 5 is synchronized with Amd2 to ISO/IEC 10646:2003 plus Sindhi additions.

Encoding forms
Functionality of encoding forms is to map every Unicode code point to a unique byte sequence. Unicode code point arrangement is the same while various encoding forms float around.
ISO/IEC 10646 defines 4 forms of encoding of universal character set: UCS-4, UCS-2, UTF-8 and UTF-16. 
Code unit: encoding of every character consists of integral number of code units. For example, for UTF-16 code unit is 16bits which means length of encoding is 16bits or 32bits.
(1) UCS-4/UTF-32
Currently, they are almost identical. It uses exactly 32bits for each code point. So it is fixed length encoding.
"This single 4-byte-long code unit corresponds to the Unicode scalar value, which is the abstract number associated with a Unicode character. "
(2) UCS-2/UTF-16
Code unit is 16 bits. Commonly used characters usually can be encoded in 1 code unit (16bits).
From wikipedia: "UTF-16: For characters in the Basic Multilingual Plane (BMP) the resulting encoding is a single 16-bit word. For characters in the other planes, the encoding will result in a pair of 16-bit words, together called a surrogate pair. All possible code points from U+0000 through U+10FFFF, except for the surrogate code points U+D800–U+DFFF (which are not characters), are uniquely mapped by UTF-16 regardless of the code point's current or future character assignment or use."
From wikipedia: "UCS-2 (2-byte Universal Character Set) is an obsolete character encoding which is a predecessor to UTF-16. The UCS-2 encoding form is nearly identical to that of UTF-16, except that it does not support surrogate pairs and therefore can only encode characters in the BMP range U+0000 through U+FFFF. As a consequence it is a fixed-length encoding that always encodes characters into a single 16-bit value."
In a word, UCS-2 is a fixed-length encoding which can encode characters in BMP range U+0000 through U+FFFF while UTF-16 is variable length encoding which supports characters in other planes by using surrogate pair.
Note:The two values FFFE16 and FFFF16 as well as the 32 values from FDD016 to FDEF16 represent noncharacters. They are invalid in interchange, but may be freely used internal to an implementation. Unpaired surrogates are invalid as well, i.e. any value in the range D80016 to DBFF16 not followed by a value in the range DC0016 to DFFF16.
(3) UTF-8
Code unit is 8 bits. It encodes one code point in one to four octets.
From wikipedia: "It is able to represent any character in the Unicode standard, yet the initial encoding of byte codes and character assignments for UTF-8 is backwards compatible with ASCII. For these reasons, it is steadily becoming the preferred encoding for e-mail, web pages"
Note: initial encoding in UTF-8 is NOT compatible with latin1(ISO-8859).

Byte Order
For UTF-16 and UTF-32, code unit is more than 1 byte. A natural problem is the byte order, big endian(MSB first) or little endian(MSB last)? For UTF-8, this problem does not exist because code unit is 1 byte. To solve this problem, Byte Order Mark(BOM) can be used. Actually, BOM does not only indicate the byte order but also define encoding form.
BOM table: From http://unicode.org/faq/utf_bom.html:

Bytes Encoding Form
00 00 FE FF UTF-32, big-endian
FF FE 00 00 UTF-32, little-endian
FE FF UTF-16, big-endian
FF FE UTF-16, little-endian
EF BB BF UTF-8

Here are some guidelines to follow(From http://unicode.org/faq/utf_bom.html):

  1. A particular protocol (e.g. Microsoft conventions for .txt files) may require use of the BOM on certain Unicode data streams, such as files. When you need to conform to such a protocol, use a BOM.
  2. Some protocols allow optional BOMs in the case of untagged text. In those cases,
    • Where a text data stream is known to be plain text, but of unknown encoding, BOM can be used as a signature. If there is no BOM, the encoding could be anything.
    • Where a text data stream is known to be plain Unicode text (but not which endian), then BOM can be used as a signature. If there is no BOM, the text should be interpreted as big-endian.
  3. Some byte oriented protocols expect ASCII characters at the beginning of a file. If UTF-8 is used with these protocols, use of the BOM as encoding form signature should be avoided. For example, bash file starting with #!/bin/sh.
  4. Where the precise type of the data stream is known (e.g. Unicode big-endian or Unicode little-endian), the BOM should not be used. In particular, whenever a data stream is declared to be UTF-16BE, UTF-16LE, UTF-32BE or UTF-32LE a BOM must not be used.

Summary:

From http://unicode.org/faq/utf_bom.html:

Name UTF-8 UTF-16 UTF-16BE UTF-16LE UTF-32 UTF-32BE UTF-32LE
Smallest code point 0000 0000 0000 0000 0000 0000 0000
Largest code point 10FFFF 10FFFF 10FFFF 10FFFF 10FFFF 10FFFF 10FFFF
Code unit size 8 bits 16 bits 16 bits 16 bits 32 bits 32 bits 32 bits
Byte order N/A <BOM> big-endian little-endian <BOM> big-endian little-endian
Minimal bytes/character 1 2 2 2 4 4 4
Maximal bytes/character 4 4 4 4 4 4 4

Note: all valid code points that are encoded are the same: from U+0000 through U+10FFFF.

More:
None of the UTFs can generate every arbitrary byte sequence. In other words, not every 4-byte-long byte sequence represents  a legal coding in UCS4.
From Unicode consortium site: "Each UTF is reversible, thus every UTF supports lossless round tripping: mapping from any Unicode coded character sequence S to a sequence of bytes and back will produce S again. To ensure round tripping, a UTF mapping  must also map all code points that are not valid Unicode characters to unique byte sequences. These invalid code points are the 66 noncharacters (including FFFE and FFFF), as well as unpaired surrogates."
This means that: to guarantee reversibility, not only valid characters but also non-valid characters must be considered and encoded appropriately.

How to fit a Unicode character into ANSII stream?
See http://unicode.org/faq/utf_bom.html#31.  Several methods are used in practice: (1) UTF-8; (2) '\uXXXX' in C or Java (3) "&#XXXX;" in HTML or XML.

Sunday, July 06, 2008

SVG tools

Official Resources:
http://www.svgi.org/
An almost comprehensive list of vector drawing programs(actually some 3d software is included as well):
http://www.maa.org/editorial/mathgames/mathgames_08_01_05.html

Free Editors:
Inkscape(most popular open source one): Besides svg, it can save file as .ps, .eps ... It also allows users to export file to .PNG(just .png, not .jpeg or .gif).
yED: a good graph editor which can automatically beautify line layout in the graph.

Standalone Viewer:
Batik Squiggle(pure Java): zoom in/out, transform... Can export .svg to .png, .jpeg and .gif.

Convertor :
ImageMagick: a powerful command line tool which provides functionalities of conversion, edition and composition. .svg can be converted to .jpg, .gif, .eps, ...

Conversion of .svg to .eps: Inkscape provides a better result than ImageMagick.

Thursday, July 03, 2008

Useful free graphic software

Some useful image processing software:
Of course, Photoshop is a good one but it is not free. Some free ones exist out there. Here is a list which introduces some excellent free image processing software. GIMP, Paint.NET, Photobie, PhotoFiltre. This site contains more software.

With popularity of web 2.0 apps, many online image processing apps emerge. I list some ones I know:
http://fotoflexer.com/
http://www.picnik.com/
https://www.photoshop.com/express/landing.html
http://www.cellsea.com/media/index.htm
http://www.creatingonline.com/Online_Image_Editor/index.html
http://www.phixr.com/photo/userindex
http://www.lunapic.com/editor/
http://www.picresize.com/

Online Image resizer/optimizer:
http://webresizer.com/
http://www.resize2mail.com/
http://www.shrinkpictures.com/
http://www.resizr.com/
http://resizr.lord-lance.com/ (only .gif is accepted)
http://www.resizeimage.4u2ges.com/
http://www.picresize.com/
http://online-image-resize.kategorie.cz/
http://rsizr.com/
http://rsizr.com/ (Crop and resize)
http://www.freeimageconverter.com/
Standalone software:
http://www.imageresizer.com/
http://bluefive.pair.com/pixresizer.htm
http://www.imageconverterplus.com/ (seems a good one, but not free)
http://adionsoft.net/fastimageresize/
http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx (MS image resizer power toy)

Vector Graphic Tools:
Inkscape, Dia, Synfig(Animation software), yED(good line layout), Sodipodi(not under active development, continue on Inkscape), Xara Xtreme for Linux, Zcubes(online vector drawing tool), Skencil(only on Unix/Linux)
Sketsa(SVG editor, not free)

Free desktop publish tool:
Scribus

Image viewer:
irfanview, xnview

Tuesday, July 01, 2008

"Hello World" Programs in different languages

Every time when we learn a new programming language, the first program is always to output "Hello World".
Someone collects "Hello World" programs written in hundreds of different languages. Check out :http://www.ntecs.de/old-hp/uu9r/lang/html/lang-all.en.html

Monday, June 30, 2008

Change font in PDT

The way to change font in PDT is not intuitive.  PDT does not support configuration of font itself. Instead, it inherits global configuration. By click "windows->preference->Apperance->Colors and Fonts", you will get:
image 

Although there are two entries related to PHP, they are useless in fact. You can not configure them. Instead, you may think configuration of entry "Basic" should work. But, you are wrong. You should configure entry "Structured Text Editors" to configure fonts which will be used by PDT PHP editor. I don't why PDT chooses to inherit font setting from "Structured Text Editors".

PHP development environment

[PHP IDE]
PHPEclipse: A plug-in of Eclipse.
PDT: a new PHP IDE which is also a plug-in of Eclipse. It is supported by Zend.
Aptana with PHP plug-in: Aptana is excellent tool to develop web2.0 applications. It excels at CSS + JS... I don't know whether its support for PHP is good as well.

[PHP Debug]
XDebug: This is a PHP extension which provides a lot of valuable debug information. Its installation is fairly simple. Users just need to download the extension, put it into PHP ext directory and modify php.ini file.
DBG PHP Debugger:
Zend Debugger: I googled and found this debugger. But I could not find related documents. So actually I don't know how to use it.

[PHP Test]
SimpleTest: A unit testing tool for PHP.

Finally, I selected PDT+Eclipse as my IDE. I found this article which describes how to debug in PDT. PHP programs can be debugged locally or on a remote server. PDT supports Zend Debugger and XDebug. PDT all-in-one package is suitable for those who want a new Eclipse+PDT+Prerequisites. If you have already installed Eclipse, you can just install PDT as plug-in. The latter is what I chose. After installing PDT, you need some configurations.
Instructions about how to configure and use all-in-one PDT package are listed here.

[Configuration of PDT]
Procedure to build PHP PDT environment not using all-in-one package:
(1) Install PHP and Debugger
To use PDT, first install PHP(I am using PHP 5.2.6). Then install corresponding PHP debugger module you choose(xdebug or zend debugger). My PHP version is 5.2.6 and I downloaded XDebug module from here. Then you need to configure PHP (modify php.ini) to use the debugger. Installation instructions about XDebug is here. After configuration, restart your web server to see whether XDebug is configured correctly. Function phpinfo() can be used. Or you can use command "php.exe -m" to list the loaded modules and XDebug should be in the Zend Module list.
(2) Configure PDT in Eclipse
If you don't use PDT all-in-one package, you need lots of configuration work.
There are two modes in which PHP can be run: script mode and web mode.
In web mode, you need a web server(e.g. Apache httpd) to host PHP applications and you can test your apps by accessing those PHP pages through browser. Generally, this is the way we publish our PHP programs when we finish.
In script mode, your PHP programs can be run by an independent executable file. PHP package provides an executable file called php.exe which can be used to execute your PHP program.
image
The most important configuration options are "Debug", "PHP Executables", "PHP Servers". 

[Run/Debug]
You can debug and run your PHP program in both modes in Eclipse. When you open Run/Debug dialog in Eclipse, following dialog should be displayed:
image
Note the two entries within red box. If you want to debug/run program as script, you should configure "PHP Executable" correctly. If you want to debug/run program on a web server, you should configure "PHP Server" correctly. Meanwhile, you should select the debugger you would like to use. This must match the debugger module you actually installed. If you install a Zend debugger for PHP while you set XDebug as your debugger in Eclipse, something unpredictable may occur.
You also can set the debug scope by clicking tab "Advanced":
image
Usage of these options is(The explanation is from help document of PDT):

  • Debug All Pages - The specified page and all the pages linked to it are debugged. The browser waits for the debug of each page before displaying it.
  • Debug First Page Only - Only the first page is debugged.
  • Start Debug from - Select the URL from which you would like the Debugging process to start.
  • Continue Debug from this Page - Selecting this option will result in all the pages linked to the URL being debugged.

When you debug PHP program in web mode(In script mode, you don't have this concern.), you must explicitly terminate the debugging process. When you click button "resume" to make the program execute until completion, the program actually does not terminate. One bug? or annoying thing is that the "Terminate" button in debug toolbar is disabled which gives users illusion that the debugged program is terminated. This illusion is natural because users don't have way to terminate the debugged program. However, the debugged app is still alive and waiting for new incoming requests. One way to terminate the debugged app is that: once more you access the debugged web page, and when the debugger stops at a breakpoint, click button "Terminate"(not button "Resume") to truly kill the debug process. Another way is that when you click an arbitrary statement in window "Debug", button "Terminate" is activated and enabled.

[Deploy]
To test programs in web mode, a web server is necessary. In my case, web server is located in my local machine as well. One way to deploy the program during development is configure Apache httpd to change its document root to point to your development root directory. However, this is not good because other applications which don't reside in your current development root will not work. My solution is to use HTTP Server configuration in Eclipse. First, I add a new HTTP server to Eclipse.
image 
Then I add the PHP application to that HTTP server:
image
When I change a source file, Eclipse will automatically publish newest version of the file to the directory specified in HTTP Server configuration. I let it point to my original Apache Httpd document root.

[Issues]
One issue I have not figured out is how to use the "Path Mapping" when PHP Server is set:
image
I don't know what that means. Hopefully, I will figure it out tomorrow.

Now, I know how to use Path Mapping.
When you run/debug your PHP page on web server, PDT needs a mapping relationship between remote document directory and current working directory. As you all know, client can not retrieve PHP source file by accessing it in browser. What is returned is output produced by PHP interpreter and web server. In other words, PDT has no way to get the PHP file you want to run/debug from remote web server. Instead, you must maintain a copy in local directory.
In my case, remote PHP URL is at http://localhost/php (I run web server on my local machine). And my Eclipse PHP working directory is different. Then I create a path mapping: "E:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php\TestPHP" => "/TestPHP"(Path in Eclipse workspace, you also can use absolute path in file system). When I access http://localhost/php/TestPHP/test.php, the file /TestPHP/test.php is displayed and traced in Eclipse debug window. The php file on remote server is debugged and local PDT communicates with remote server/debugger by specific debugging protocol. Apache http server will check the existence of requested php file before it transfers processing control to PHP interpreter. If no corresponding php file is found by web server, error message is returned. If content of file on remote server and content of local file is different, weird behaviors may occur. Generally, they should be identical.  To sum up, debugging occurs on remote server and PDT uses local php source file to display debug information and let user control (step in, step over...) the progress of debugging.

Some Useful Open Source Screen Capture Apps

When I write an article on my blog using WLW, generally I need to insert some links, pictures... WLW provides good support for insertion of various resources(link, picture, map, tag, video, code snippet...). However, I still need some standalone software which can make my work more convenient. Sometimes, I need to take a screen shot. Using PrtSc key + MS Paint is a solution which I have been using. However, more powerful tool is preferred. During I surfed on the web, I found some valuable software. And something important is that they are free!!!

Wink: A excellent screen capture software which eases creation of tutorial and presentation. Moreover, users can add explanations, buttons etc to the tutorial/presentation. Supported output formats are .swf, .exe, .pdf, .html and postscript. Users can customize the region to capture. One nice feature is input-driven capture. It means tha Wink only captures the specific region when a user clicks/moves mouse or strokes a key. This feature enhances performance obviously and makes output file size smaller because it removes some possible duplicate frames.

CamStudio: Another free screen capture software. I haven't used it so I will not say more about it.

XVidcap: Another good one.

XnView: A good and simple app which can manage your pictures. Besides, it provides some extra functionalities like simple picture processing(crop, resize, slideshow...)... One interesting feature is that it supports screen capture. At first glance, I think it is just a simple add-on feature which does not make much sense compared to other excellent features. However, when I used it, It provides a good feature which greatly solves my problem. Sometimes, I want to capture a specific window(e.g. Explorer, Browser...). Usual way is to capture whole desktop and then crop it in MS Paint. This procedure is tedious. XnView's screen capture provides a way to capture specific window. Moreover, you can exclude the title bar of the window... See the screen shot
image 

There are many more screen capture software out there on the web, e.g. ZScreen, Greenshot, capturedit, Sigis, AutoScreen, Taksi, Jacareto...
The basic functionality of these software is capture of entire window, customized region and a specific window. Some apps provide simple image edit features. I found Greenshot is what I want.

Finally, I found something ironical. Windows built-in screen capture support capture of active window.
(1) When you press PrtSc key, entire desktop is captured.
(2) When you press Alt + PrtSc key, only active window is captured.
There some useful tips about screen capture here.

 

Sunday, June 01, 2008

AutoHotKey

AutoHotKey is an excellent which can customize keyboard/mouse shortcuts. It provides a simple script language which can be used to write scripts describing keyboard/mouse shortcuts. I am surprised that AutoHotKey provides abundant functionality which can be used in your scripts, e.g. get a file from a URL address, read/write file, control all aspects of window...

Besides, there are some available scripts on line which implement some common requirements, like window drag...
You can see some good ones here. If you want more, this forum includes thousands of scripts.

Among them, I found Niftywindow is a free one which implements lots of new functionality. So I downloaded it and modified the source file to fit in my need. It provides so many features so that some of them will not be used frequently. I chose some shortcuts which would be used by me in everyday using.

Saturday, May 03, 2008

Differences of array and pointer in C/C++

(1) Array

int main(){
    char *p = "hello,world";
    char *p2 = "hello,worldc";
    char str[] = "hello,world";
    char str2[] = "hello,world";    
    printf("%x %x %x %x\n", p, p2, str, str2);

}

Sample output(compiled with GCC 4.1.2 on Ubuntu 6.06.1LTS):

804856c 8048578 bf879674 bf879668

Conclusions:
<1> Strings pointed by pointers p and p2 are allocated in different places from strings of str and str2. The first and second strings are allocatd to static memory area and these two strings can not be modified. So the following statement makes the program crash(run time error instead of compilation time):
    p[0] = 'd'
The third and fourth strings are allocated on stack.  They can be modified. They just exist in current function call and after this function is executed they are discarded and should not be referenced any more.
<2> Pointers can be modified arbitrarily while array variables can not be modified.
Following code is illegal:

    char str[] = "hello,world";
    char str2[] = "abcdefgh";
    str = str2;    //illegal, can not be compiled successfully.
str++; //illegal
str+1; //legal, just like an ordinary addition.

In other words, array name is a reference to an array and it represents the array.  It is kind of a contant.
<3> Array name cannot be used a left value. Array name can be used as pointer if it acts as right value. Pointer can not be cast to array!!!
<4> Apply sizeof to array name, you will get size of the array. Apply sizeofi to a pointer, you will get size of the pointer(generally, four bytes).
<5> Array must be initialized and corresponding memory is allocated.
<6> void function(type array[]) is equivalent to void function(type *pointer).

数组要么在静态存储区被创建(如全局数组),要么在栈上被创建。数组名对应着(而不是指向)一块内存,其地址与容量在生命期内保持不变,只有数组的内容可以改变。
指针可以随时指向任意类型的内存块,它的特征是“可变”,所以我们常用指针来操作动态内存。指针远比数组灵活,但也更危险。
不能对数组名进行直接复制与比较。示例7-3-2中,若想把数组a的内容复制给数组b,不能用语句 b = a ,否则将产生编译错误。
当数组作为函数的参数进行传递时,该数组自动退化为同类型的指针.
对数组名sizeof()得到的是数组所占的大小,而对指针sizeof()得到的是指针内容所占的字节数。
数组定义时必须初始化并分配空间,而指针定义时可以不初始化。
如果将数组或指针作为自定义函数的形参,此时数组名和指针完全等价.在函数体内可以用数组名进行自增或赋值等运算,因为在一般的编译程序中,将函数的形参数组编译成指针.既f(char Data[])====>f(char *Data)