C/C++拾遺————空指針{NULL/0/(void*)0}與 空字符{null/'0'} 區別

 

 

突然對NULL與null的區別有點疑惑,在網上搜索了一下,查到下面的用法。其實很簡單,就如博文標題,空指針可以是NULL,0或者(void*)0,空字符可以是null或者‘0’表示。

 

When the term "null" or "NULL" is casually used, one of several things may be meant:

  1. The conceptual null pointer, the abstract language concept defined in question 1.1 It is implemented with...
  2. The internal (or run-time) representation of a null pointer, which may or may not be all-bits-0 and which may be different for different pointer types. The actual values should be of concern only to compiler writers. Authors of C programs never see them, since they use...
  3. The source code syntax for null pointers, which is the single character "0". It is often hidden behind...
  4. The NULL macro, which is #defined to be "0" or "(void*)0"Finally, as red herrings, we have...
  5. The ASCII null character (NUL), which does have all bits zero, but has no necessary relation to the null pointer except in name; and...
  6. The "null string," which is another name for an empty string ("").  The term "null string" can be confusing in C (and should perhaps be avoided), because it involves a null ('\0') character, but not a null pointer, which brings us full circle...

This article always uses the phrase "null pointer" (in lower case) for sense 1, the character "0" for sense 3, and the capitalized word "NULL" for sense 4.

 

 

參考鏈接:

http://www.lysator.liu.se/c/c-faq/c-1.html


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章