[go: nahoru, domu]

删除的内容 添加的内容
Yunyiyang留言 | 贡献
内容扩充 调整格式、排版
Yunyiyang留言 | 贡献
调整格式、排版
第312行:
=== 函数 ===
C语言的基本结构单位是函数<ref name="C18"/>。系统首先调用 [[主函式#C/C++|main函数(主函数)]],通过函数的嵌套调用,再调用其他函数。函数可以是系统自带的函数,也可以是用户定义的函数。C语言中,不允许函数嵌套定义。
 
=== 保留关键字 ===
以下是ANSI/ISO C标准中定义的C语言的保留关键字:<ref>{{Cite web|url=https://www.iso.org/standard/57853.html|title=ISO/IEC 9899:2011|publisher=International Organization for Standardization|accessdate=2020-03-08|language=en|archiveurl=https://web.archive.org/web/20200328063511/https://www.iso.org/standard/57853.html|archivedate=2020-03-28|dead-url=no}}</ref>
 
{| class="wikitable" border="1" width="500" cellpadding="0" cellspacing="0"
|-----
| width="25%" | <tt>char</tt> || width="25%" | <tt>short</tt>
| width="25%" | <tt>int</tt> || width="25%" | <tt>unsigned</tt>
|-----
| width="25%" | <tt>long</tt> || width="25%" | <tt>float</tt>
| width="25%" | <tt>double</tt> || width="25%" | <tt>struct</tt>
|-----
| width="25%" | <tt>union</tt> || width="25%" | <tt>void</tt>
| width="25%" | <tt>enum</tt> || width="25%" | <tt>signed</tt>
|-----
| width="25%" | <tt>const</tt> || width="25%" | <tt>[[Volatile变量|volatile]]</tt>
| width="25%" | <tt>[[typedef]]</tt> || width="25%" | <tt>auto</tt>
|-----
| width="25%" | <tt>register</tt> || width="25%" | <tt>static</tt>
| width="25%" | <tt>extern</tt> || width="25%" | <tt>break</tt>
|-----
| width="25%" | <tt>case</tt> || width="25%" | <tt>continue</tt>
| width="25%" | <tt>default</tt> || width="25%" | <tt>do</tt>
|-----
| width="25%" | <tt>else</tt> || width="25%" | <tt>for</tt>
| width="25%" | <tt>goto</tt> || width="25%" | <tt>if</tt>
|-----
| width="25%" | <tt>return</tt> || width="25%" | <tt>switch</tt>
| width="25%" | <tt>while</tt> || width="25%" | <tt>sizeof</tt>
|}
<!-- sizeof不属于关键字,只属于运算符 -->
=== C99标准新增了以下关键字 ===
{| class="wikitable" border="1" width="500" cellpadding="0" cellspacing="0"
|-----
| width="20%" | <tt>_Bool</tt> || width="20%" | <tt>_Complex </tt>
| width="20%" | <tt>_Imaginary</tt> || width="20%" | <tt>inline</tt>|| width="20%" | <tt>restrict</tt>
|}
=== C11标准新增了以下关键字 ===
{| class="wikitable" border="1" width="500" cellpadding="0" cellspacing="0"
|-----
| width="20%" | <tt>_Alignas</tt> || width="20%" | <tt>_Alignof </tt>
| width="20%" | <tt>_Atomic</tt> || width="20%" | <tt>_Generic</tt>|| width="20%" | <tt>_Noreturn</tt>
|-----
| width="25%" | <tt>_Static_assert</tt>|| width="25%" | <tt>_Thread_local</tt>
|}
 
== Hello World 程序 ==
第347行 ⟶ 第392行:
 
== 内存管理 ==
C语言的特色之一是:程序员必须亲自处理内存的分配细节。语言不负责内存边界检查,这是因为在运行时进行内存边界检查会造成[[性能问题]],与[[Unix哲学|UNIX哲学]]不符。此特性容易导致[[缓冲区溢出]]问题。然而,部分编译器(如英特尔编译器)会出于安全性的考量,提供方法以进行运行时内存边界检查<ref>{{cite web |title=check-pointers, Qcheck-pointers |url=https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/data-options/check-pointers-qcheck-pointers.html |website=Intel |accessdate=2021-06-01 |language=en}}</ref>。
C语言的特色之一是:程序员必须亲自处理内存的分配细节。
 
大多数C语言实现使用栈(Stack)来保存函数返回地址/栈帧基址、完成函数的参数传递和函数局部变量的存储。然而,在部分极特殊的平台上,使用栈并不能获得最大效率。此时的实现由编译器决定<ref name="C18"/>。
第369行 ⟶ 第414行:
 
使用[[堆]](Heap)内存将带来额外的开销和风险。
 
== 安全问题 ==
C语言的特色之一是:语言不负责内存边界检查,这是因为在运行时进行内存边界检查会造成[[性能问题]],与[[Unix哲学|UNIX哲学]]不符。此特性容易导致[[缓冲区溢出]]问题。然而,部分编译器(如英特尔编译器)会出于安全性的考量,提供方法以进行运行时内存边界检查<ref>{{cite web |title=check-pointers, Qcheck-pointers |url=https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/data-options/check-pointers-qcheck-pointers.html |website=Intel |accessdate=2021-06-01 |language=en}}</ref>。
 
== 库 ==
第443行 ⟶ 第485行:
 
使用像[[Valgrind]]或{{link-en|IBM Rational Purify|Purify}}等軟體工具,或者連結有特別[[malloc]]函式的程式庫,有助於找出一些運行期記憶體使用的問題。
 
== 保留关键字 ==
以下是C语言的保留关键字:<ref>{{Cite web|url=https://www.iso.org/standard/57853.html|title=ISO/IEC 9899:2011|publisher=International Organization for Standardization|accessdate=2020-03-08|language=en|archiveurl=https://web.archive.org/web/20200328063511/https://www.iso.org/standard/57853.html|archivedate=2020-03-28|dead-url=no}}</ref>
 
{| class="wikitable" border="1" width="500" cellpadding="0" cellspacing="0"
|-----
| width="25%" | <tt>char</tt> || width="25%" | <tt>short</tt>
| width="25%" | <tt>int</tt> || width="25%" | <tt>unsigned</tt>
|-----
| width="25%" | <tt>long</tt> || width="25%" | <tt>float</tt>
| width="25%" | <tt>double</tt> || width="25%" | <tt>struct</tt>
|-----
| width="25%" | <tt>union</tt> || width="25%" | <tt>void</tt>
| width="25%" | <tt>enum</tt> || width="25%" | <tt>signed</tt>
|-----
| width="25%" | <tt>const</tt> || width="25%" | <tt>[[Volatile变量|volatile]]</tt>
| width="25%" | <tt>[[typedef]]</tt> || width="25%" | <tt>auto</tt>
|-----
| width="25%" | <tt>register</tt> || width="25%" | <tt>static</tt>
| width="25%" | <tt>extern</tt> || width="25%" | <tt>break</tt>
|-----
| width="25%" | <tt>case</tt> || width="25%" | <tt>continue</tt>
| width="25%" | <tt>default</tt> || width="25%" | <tt>do</tt>
|-----
| width="25%" | <tt>else</tt> || width="25%" | <tt>for</tt>
| width="25%" | <tt>goto</tt> || width="25%" | <tt>if</tt>
|-----
| width="25%" | <tt>return</tt> || width="25%" | <tt>switch</tt>
| width="25%" | <tt>while</tt> || width="25%" | <tt>sizeof</tt>
|}
<!-- sizeof不属于关键字,只属于运算符 -->
=== C99新增关键字 ===
{| class="wikitable" border="1" width="500" cellpadding="0" cellspacing="0"
|-----
| width="20%" | <tt>_Bool</tt> || width="20%" | <tt>_Complex </tt>
| width="20%" | <tt>_Imaginary</tt> || width="20%" | <tt>inline</tt>|| width="20%" | <tt>restrict</tt>
|}
=== C11新增关键字 ===
{| class="wikitable" border="1" width="500" cellpadding="0" cellspacing="0"
|-----
| width="20%" | <tt>_Alignas</tt> || width="20%" | <tt>_Alignof </tt>
| width="20%" | <tt>_Atomic</tt> || width="20%" | <tt>_Generic</tt>|| width="20%" | <tt>_Noreturn</tt>
|-----
| width="25%" | <tt>_Static_assert</tt>|| width="25%" | <tt>_Thread_local</tt>
|}
 
== 經典錯誤 ==